]>
Commit | Line | Data |
---|---|---|
804405e7 | 1 | /*+++\r |
2 | \r | |
f9b8ab56 HT |
3 | Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials \r | |
804405e7 | 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 | UnixBusDriver.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
2ff79f2e | 18 | This following section documents the environment variables for the UNIX \r |
804405e7 | 19 | build. These variables are used to define the (virtual) hardware \r |
20 | configuration of the UNIX 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_UNIX_PHYSICAL_DISKS - maps to drives on your system\r | |
26 | EFI_UNIX_VIRTUAL_DISKS - maps to a device emulated by a file\r | |
27 | EFI_UNIX_FILE_SYSTEM - mouts a directory as a file system\r | |
28 | EFI_UNIX_CONSOLE - make a logical comand line window (only one!)\r | |
29 | EFI_UNIX_UGA - Builds UGA Windows of Width and Height\r | |
30 | \r | |
31 | <F>ixed - Fixed disk like a hard drive.\r | |
32 | <R>emovable - Removable media like a floppy or CD-ROM.\r | |
33 | Read <O>nly - Write protected device.\r | |
34 | Read <W>rite - Read write device.\r | |
35 | <block count> - Decimal number of blocks a device supports.\r | |
36 | <block size> - Decimal number of bytes per block.\r | |
37 | \r | |
38 | UNIX envirnonment variable contents. '<' and '>' are not part of the variable, \r | |
39 | they are just used to make this help more readable. There should be no \r | |
40 | spaces between the ';'. Extra spaces will break the variable. A '!' is \r | |
41 | used to seperate multiple devices in a variable.\r | |
42 | \r | |
43 | EFI_UNIX_VIRTUAL_DISKS = \r | |
44 | <F | R><O | W>;<block count>;<block size>[!...]\r | |
45 | \r | |
46 | EFI_UNIX_PHYSICAL_DISKS =\r | |
47 | <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]\r | |
48 | \r | |
49 | Virtual Disks: These devices use a file to emulate a hard disk or removable\r | |
50 | media device. \r | |
51 | \r | |
52 | Thus a 20 MB emulated hard drive would look like:\r | |
53 | EFI_UNIX_VIRTUAL_DISKS=FW;40960;512\r | |
54 | \r | |
55 | A 1.44MB emulated floppy with a block size of 1024 would look like:\r | |
56 | EFI_UNIX_VIRTUAL_DISKS=RW;1440;1024\r | |
57 | \r | |
58 | Physical Disks: These devices use UNIX to open a real device in your system\r | |
59 | \r | |
60 | Thus a 120 MB floppy would look like:\r | |
61 | EFI_UNIX_PHYSICAL_DISKS=B:RW;245760;512\r | |
62 | \r | |
63 | Thus a standard CD-ROM floppy would look like:\r | |
64 | EFI_UNIX_PHYSICAL_DISKS=Z:RO;307200;2048\r | |
65 | \r | |
66 | EFI_UNIX_FILE_SYSTEM = \r | |
67 | <directory path>[!...]\r | |
68 | \r | |
69 | Mounting the two directories C:\FOO and C:\BAR would look like:\r | |
70 | EFI_UNIX_FILE_SYSTEM=c:\foo!c:\bar\r | |
71 | \r | |
72 | EFI_UNIX_CONSOLE = \r | |
73 | <window title>\r | |
74 | \r | |
75 | Declaring a text console window with the title "My EFI Console" woild look like:\r | |
76 | EFI_UNIX_CONSOLE=My EFI Console\r | |
77 | \r | |
78 | EFI_UNIX_UGA = \r | |
79 | <width> <height>[!...]\r | |
80 | \r | |
81 | Declaring a two UGA windows with resolutions of 800x600 and 1024x768 would look like:\r | |
82 | Example : EFI_UNIX_UGA=800 600!1024 768\r | |
83 | \r | |
84 | EFI_UNIX_PASS_THROUGH =\r | |
85 | <BaseAddress>;<Bus#>;<Device#>;<Function#>\r | |
86 | \r | |
87 | Declaring a base address of 0xE0000000 (used for PCI Express devices)\r | |
88 | and having NT32 talk to a device located at bus 0, device 1, function 0:\r | |
89 | Example : EFI_UNIX_PASS_THROUGH=E000000;0;1;0\r | |
90 | \r | |
91 | ---*/\r | |
92 | \r | |
93 | #include "UnixBusDriver.h"\r | |
94 | \r | |
95 | //\r | |
96 | // Define GUID for the Unix Bus Driver\r | |
97 | //\r | |
7492c63d | 98 | EFI_GUID gUnixBusDriverGuid = {\r |
804405e7 | 99 | 0x419f582, 0x625, 0x4531, {0x8a, 0x33, 0x85, 0xa9, 0x96, 0x5c, 0x95, 0xbc}\r |
100 | };\r | |
101 | \r | |
102 | //\r | |
103 | // DriverBinding protocol global\r | |
104 | //\r | |
105 | EFI_DRIVER_BINDING_PROTOCOL gUnixBusDriverBinding = {\r | |
106 | UnixBusDriverBindingSupported,\r | |
107 | UnixBusDriverBindingStart,\r | |
108 | UnixBusDriverBindingStop,\r | |
109 | 0xa,\r | |
110 | NULL,\r | |
111 | NULL\r | |
112 | };\r | |
113 | \r | |
114 | #define UNIX_PCD_ARRAY_SIZE (sizeof(mPcdEnvironment)/sizeof(UNIX_PCD_ENTRY))\r | |
115 | \r | |
116 | //\r | |
117 | // Table to map UNIX Environment variable to the GUID that should be in\r | |
118 | // device path.\r | |
119 | //\r | |
7492c63d | 120 | UNIX_PCD_ENTRY mPcdEnvironment[] = {\r |
2ff79f2e | 121 | {PcdToken(PcdUnixConsole), &gEfiUnixConsoleGuid},\r |
122 | {PcdToken(PcdUnixUga), &gEfiUnixUgaGuid},\r | |
123 | {PcdToken(PcdUnixGop), &gEfiUnixGopGuid},\r | |
124 | {PcdToken(PcdUnixFileSystem), &gEfiUnixFileSystemGuid},\r | |
125 | {PcdToken(PcdUnixSerialPort), &gEfiUnixSerialPortGuid},\r | |
126 | {PcdToken(PcdUnixVirtualDisk), &gEfiUnixVirtualDisksGuid},\r | |
127 | {PcdToken(PcdUnixPhysicalDisk), &gEfiUnixPhysicalDisksGuid},\r | |
128 | {PcdToken(PcdUnixCpuModel), &gEfiUnixCPUModelGuid},\r | |
129 | {PcdToken(PcdUnixCpuSpeed), &gEfiUnixCPUSpeedGuid},\r | |
130 | {PcdToken(PcdUnixMemorySize), &gEfiUnixMemoryGuid},\r | |
131 | {PcdToken(PcdUnixNetworkInterface), &gEfiUnixNetworkGuid}\r | |
804405e7 | 132 | };\r |
133 | \r | |
134 | VOID *\r | |
135 | AllocateMemory (\r | |
136 | IN UINTN Size\r | |
137 | )\r | |
138 | {\r | |
139 | EFI_STATUS Status;\r | |
140 | VOID *Buffer;\r | |
141 | \r | |
142 | Status = gBS->AllocatePool (\r | |
143 | EfiBootServicesData,\r | |
144 | Size,\r | |
145 | (VOID *)&Buffer\r | |
146 | );\r | |
147 | if (EFI_ERROR (Status)) {\r | |
148 | ASSERT (FALSE);\r | |
149 | return NULL;\r | |
150 | }\r | |
151 | return Buffer;\r | |
152 | }\r | |
153 | \r | |
154 | \r | |
155 | EFI_STATUS\r | |
156 | EFIAPI\r | |
157 | UnixBusDriverBindingSupported (\r | |
158 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
159 | IN EFI_HANDLE ControllerHandle,\r | |
160 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
161 | )\r | |
162 | /*++\r | |
163 | \r | |
164 | Routine Description:\r | |
165 | \r | |
166 | Arguments:\r | |
167 | \r | |
168 | Returns:\r | |
169 | \r | |
170 | None\r | |
171 | \r | |
172 | --*/\r | |
804405e7 | 173 | {\r |
174 | EFI_STATUS Status;\r | |
175 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
176 | EFI_UNIX_THUNK_PROTOCOL *UnixThunk;\r | |
177 | UINTN Index;\r | |
178 | \r | |
179 | //\r | |
180 | // Check the contents of the first Device Path Node of RemainingDevicePath to make sure\r | |
181 | // it is a legal Device Path Node for this bus driver's children.\r | |
182 | //\r | |
183 | if (RemainingDevicePath != NULL) {\r | |
af4a6385 | 184 | //\r |
185 | // Check if RemainingDevicePath is the End of Device Path Node, \r | |
186 | // if yes, go on checking other conditions\r | |
187 | //\r | |
188 | if (!IsDevicePathEnd (RemainingDevicePath)) {\r | |
189 | //\r | |
190 | // If RemainingDevicePath isn't the End of Device Path Node,\r | |
191 | // check its validation\r | |
192 | //\r | |
193 | if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||\r | |
194 | RemainingDevicePath->SubType != HW_VENDOR_DP ||\r | |
195 | DevicePathNodeLength(RemainingDevicePath) != sizeof(UNIX_VENDOR_DEVICE_PATH_NODE)) {\r | |
196 | return EFI_UNSUPPORTED;\r | |
197 | }\r | |
198 | \r | |
199 | for (Index = 0; Index < UNIX_PCD_ARRAY_SIZE; Index++) {\r | |
200 | if (CompareGuid (&((VENDOR_DEVICE_PATH *) RemainingDevicePath)->Guid, mPcdEnvironment[Index].DevicePathGuid)) {\r | |
201 | break;\r | |
202 | }\r | |
203 | }\r | |
204 | \r | |
205 | if (Index >= UNIX_PCD_ARRAY_SIZE) {\r | |
206 | return EFI_UNSUPPORTED;\r | |
804405e7 | 207 | }\r |
804405e7 | 208 | }\r |
209 | }\r | |
210 | \r | |
211 | //\r | |
212 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
213 | //\r | |
214 | Status = gBS->OpenProtocol (\r | |
215 | ControllerHandle,\r | |
af4a6385 | 216 | &gEfiUnixThunkProtocolGuid,\r |
217 | (VOID **)&UnixThunk,\r | |
804405e7 | 218 | This->DriverBindingHandle,\r |
219 | ControllerHandle,\r | |
220 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
221 | );\r | |
222 | if (Status == EFI_ALREADY_STARTED) {\r | |
223 | return EFI_SUCCESS;\r | |
224 | }\r | |
225 | \r | |
226 | if (EFI_ERROR (Status)) {\r | |
227 | return Status;\r | |
228 | }\r | |
229 | \r | |
af4a6385 | 230 | //\r |
231 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
232 | //\r | |
804405e7 | 233 | gBS->CloseProtocol (\r |
234 | ControllerHandle,\r | |
af4a6385 | 235 | &gEfiUnixThunkProtocolGuid,\r |
804405e7 | 236 | This->DriverBindingHandle,\r |
237 | ControllerHandle\r | |
238 | );\r | |
239 | \r | |
af4a6385 | 240 | //\r |
241 | // Open the EFI Device Path protocol needed to perform the supported test\r | |
242 | //\r | |
804405e7 | 243 | Status = gBS->OpenProtocol (\r |
244 | ControllerHandle,\r | |
af4a6385 | 245 | &gEfiDevicePathProtocolGuid,\r |
246 | (VOID **)&ParentDevicePath,\r | |
804405e7 | 247 | This->DriverBindingHandle,\r |
248 | ControllerHandle,\r | |
249 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
250 | );\r | |
251 | if (Status == EFI_ALREADY_STARTED) {\r | |
252 | return EFI_SUCCESS;\r | |
253 | }\r | |
254 | \r | |
255 | if (EFI_ERROR (Status)) {\r | |
256 | return Status;\r | |
257 | }\r | |
258 | \r | |
259 | //\r | |
260 | // Since we call through UnixThunk we need to make sure it's valid\r | |
261 | //\r | |
262 | Status = EFI_SUCCESS;\r | |
263 | if (UnixThunk->Signature != EFI_UNIX_THUNK_PROTOCOL_SIGNATURE) {\r | |
264 | Status = EFI_UNSUPPORTED;\r | |
265 | }\r | |
266 | \r | |
7ee3b613 | 267 | //\r |
af4a6385 | 268 | // Close protocol, don't use device path protocol in the Support() function\r |
804405e7 | 269 | //\r |
270 | gBS->CloseProtocol (\r | |
271 | ControllerHandle,\r | |
af4a6385 | 272 | &gEfiDevicePathProtocolGuid,\r |
804405e7 | 273 | This->DriverBindingHandle,\r |
274 | ControllerHandle\r | |
275 | );\r | |
276 | \r | |
277 | return Status;\r | |
278 | }\r | |
279 | \r | |
280 | EFI_STATUS\r | |
281 | EFIAPI\r | |
282 | UnixBusDriverBindingStart (\r | |
283 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
284 | IN EFI_HANDLE ControllerHandle,\r | |
285 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
286 | )\r | |
287 | /*++\r | |
288 | \r | |
289 | Routine Description:\r | |
290 | \r | |
291 | Arguments:\r | |
292 | \r | |
293 | Returns:\r | |
294 | \r | |
295 | None\r | |
296 | \r | |
297 | --*/\r | |
804405e7 | 298 | {\r |
299 | EFI_STATUS Status;\r | |
300 | EFI_STATUS InstallStatus;\r | |
301 | EFI_UNIX_THUNK_PROTOCOL *UnixThunk;\r | |
302 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
303 | UNIX_BUS_DEVICE *UnixBusDevice;\r | |
304 | UNIX_IO_DEVICE *UnixDevice;\r | |
305 | UINTN Index;\r | |
306 | CHAR16 *StartString;\r | |
307 | CHAR16 *SubString;\r | |
308 | UINT16 Count;\r | |
309 | UINTN StringSize;\r | |
310 | UINT16 ComponentName[MAX_UNIX_ENVIRNMENT_VARIABLE_LENGTH];\r | |
311 | UNIX_VENDOR_DEVICE_PATH_NODE *Node;\r | |
312 | BOOLEAN CreateDevice;\r | |
313 | CHAR16 *TempStr;\r | |
314 | CHAR16 *PcdTempStr;\r | |
315 | UINTN TempStrSize;\r | |
316 | \r | |
317 | Status = EFI_UNSUPPORTED;\r | |
318 | \r | |
319 | //\r | |
320 | // Grab the protocols we need\r | |
321 | //\r | |
322 | Status = gBS->OpenProtocol (\r | |
323 | ControllerHandle,\r | |
324 | &gEfiDevicePathProtocolGuid,\r | |
325 | (VOID **)&ParentDevicePath,\r | |
326 | This->DriverBindingHandle,\r | |
327 | ControllerHandle,\r | |
328 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
329 | );\r | |
330 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r | |
331 | return Status;\r | |
332 | }\r | |
333 | \r | |
334 | Status = gBS->OpenProtocol (\r | |
335 | ControllerHandle,\r | |
336 | &gEfiUnixThunkProtocolGuid,\r | |
337 | (VOID **)&UnixThunk,\r | |
338 | This->DriverBindingHandle,\r | |
339 | ControllerHandle,\r | |
340 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
341 | );\r | |
342 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r | |
343 | return Status;\r | |
344 | }\r | |
345 | \r | |
346 | if (Status != EFI_ALREADY_STARTED) {\r | |
347 | Status = gBS->AllocatePool (\r | |
348 | EfiBootServicesData,\r | |
349 | sizeof (UNIX_BUS_DEVICE),\r | |
350 | (VOID *) &UnixBusDevice\r | |
351 | );\r | |
352 | if (EFI_ERROR (Status)) {\r | |
353 | return Status;\r | |
354 | }\r | |
355 | \r | |
356 | UnixBusDevice->Signature = UNIX_BUS_DEVICE_SIGNATURE;\r | |
357 | UnixBusDevice->ControllerNameTable = NULL;\r | |
358 | \r | |
359 | AddUnicodeString (\r | |
360 | "eng",\r | |
361 | gUnixBusDriverComponentName.SupportedLanguages,\r | |
362 | &UnixBusDevice->ControllerNameTable,\r | |
363 | L"Unix Bus Controller"\r | |
364 | );\r | |
365 | \r | |
366 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
367 | &ControllerHandle,\r | |
368 | &gUnixBusDriverGuid,\r | |
369 | UnixBusDevice,\r | |
370 | NULL\r | |
371 | );\r | |
372 | if (EFI_ERROR (Status)) {\r | |
373 | FreeUnicodeStringTable (UnixBusDevice->ControllerNameTable);\r | |
374 | gBS->FreePool (UnixBusDevice);\r | |
375 | return Status;\r | |
376 | }\r | |
377 | }\r | |
378 | \r | |
379 | //\r | |
380 | // Loop on the Variable list. Parse each variable to produce a set of handles that\r | |
381 | // represent virtual hardware devices.\r | |
382 | //\r | |
383 | InstallStatus = EFI_NOT_FOUND;\r | |
384 | for (Index = 0; Index < UNIX_PCD_ARRAY_SIZE; Index++) {\r | |
385 | PcdTempStr = (VOID *)LibPcdGetPtr (mPcdEnvironment[Index].Token);\r | |
386 | ASSERT (PcdTempStr != NULL);\r | |
387 | \r | |
388 | TempStrSize = StrLen (PcdTempStr);\r | |
389 | TempStr = AllocateMemory ((TempStrSize * sizeof (CHAR16)) + 1);\r | |
390 | StrCpy (TempStr, PcdTempStr);\r | |
391 | \r | |
392 | StartString = TempStr;\r | |
393 | \r | |
394 | //\r | |
2ff79f2e | 395 | // Parse the environment variable into sub strings using '!' as a delimator.\r |
804405e7 | 396 | // Each substring needs it's own handle to be added to the system. This code\r |
397 | // does not understand the sub string. Thats the device drivers job.\r | |
398 | //\r | |
399 | Count = 0;\r | |
400 | while (*StartString != '\0') {\r | |
401 | \r | |
402 | //\r | |
403 | // Find the end of the sub string\r | |
404 | //\r | |
405 | SubString = StartString;\r | |
406 | while (*SubString != '\0' && *SubString != '!') {\r | |
407 | SubString++;\r | |
408 | }\r | |
409 | \r | |
410 | if (*SubString == '!') {\r | |
411 | //\r | |
412 | // Replace token with '\0' to make sub strings. If this is the end\r | |
413 | // of the string SubString will already point to NULL.\r | |
414 | //\r | |
415 | *SubString = '\0';\r | |
416 | SubString++;\r | |
417 | }\r | |
418 | \r | |
419 | CreateDevice = TRUE;\r | |
420 | if (RemainingDevicePath != NULL) {\r | |
421 | CreateDevice = FALSE;\r | |
af4a6385 | 422 | //\r |
423 | // Check if RemainingDevicePath is the End of Device Path Node, \r | |
424 | // if yes, don't create any child device \r | |
425 | //\r | |
426 | if (!IsDevicePathEnd (RemainingDevicePath)) {\r | |
427 | //\r | |
428 | // If RemainingDevicePath isn't the End of Device Path Node,\r | |
429 | // check its validation\r | |
430 | //\r | |
431 | Node = (UNIX_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;\r | |
432 | if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&\r | |
433 | Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&\r | |
434 | DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)\r | |
804405e7 | 435 | ) {\r |
af4a6385 | 436 | if (CompareGuid (&Node->VendorDevicePath.Guid, mPcdEnvironment[Index].DevicePathGuid) &&\r |
437 | Node->Instance == Count\r | |
438 | ) {\r | |
439 | CreateDevice = TRUE;\r | |
440 | }\r | |
804405e7 | 441 | }\r |
442 | }\r | |
443 | }\r | |
444 | \r | |
445 | if (CreateDevice) {\r | |
446 | //\r | |
447 | // Allocate instance structure, and fill in parent information.\r | |
448 | //\r | |
449 | UnixDevice = AllocateMemory (sizeof (UNIX_IO_DEVICE));\r | |
450 | if (UnixDevice == NULL) {\r | |
451 | return EFI_OUT_OF_RESOURCES;\r | |
452 | }\r | |
453 | \r | |
454 | UnixDevice->Handle = NULL;\r | |
455 | UnixDevice->ControllerHandle = ControllerHandle;\r | |
456 | UnixDevice->ParentDevicePath = ParentDevicePath;\r | |
457 | \r | |
458 | UnixDevice->UnixIo.UnixThunk = UnixThunk;\r | |
459 | \r | |
460 | //\r | |
461 | // Plus 2 to account for the NULL at the end of the Unicode string\r | |
462 | //\r | |
463 | StringSize = (UINTN) ((UINT8 *) SubString - (UINT8 *) StartString) + sizeof (CHAR16);\r | |
464 | UnixDevice->UnixIo.EnvString = AllocateMemory (StringSize);\r | |
465 | if (UnixDevice->UnixIo.EnvString != NULL) {\r | |
466 | CopyMem (UnixDevice->UnixIo.EnvString, StartString, StringSize);\r | |
467 | }\r | |
468 | \r | |
469 | UnixDevice->ControllerNameTable = NULL;\r | |
470 | \r | |
2ac288f9 | 471 | // FIXME: check size\r |
804405e7 | 472 | StrCpy(ComponentName, UnixDevice->UnixIo.EnvString);\r |
473 | \r | |
474 | UnixDevice->DevicePath = UnixBusCreateDevicePath (\r | |
475 | ParentDevicePath,\r | |
476 | mPcdEnvironment[Index].DevicePathGuid,\r | |
477 | Count\r | |
478 | );\r | |
479 | if (UnixDevice->DevicePath == NULL) {\r | |
480 | gBS->FreePool (UnixDevice);\r | |
481 | return EFI_OUT_OF_RESOURCES;\r | |
482 | }\r | |
483 | \r | |
484 | AddUnicodeString (\r | |
485 | "eng",\r | |
486 | gUnixBusDriverComponentName.SupportedLanguages,\r | |
487 | &UnixDevice->ControllerNameTable,\r | |
488 | ComponentName\r | |
489 | );\r | |
490 | \r | |
491 | UnixDevice->UnixIo.TypeGuid = mPcdEnvironment[Index].DevicePathGuid;\r | |
492 | UnixDevice->UnixIo.InstanceNumber = Count;\r | |
493 | \r | |
494 | UnixDevice->Signature = UNIX_IO_DEVICE_SIGNATURE;\r | |
495 | \r | |
496 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
497 | &UnixDevice->Handle,\r | |
498 | &gEfiDevicePathProtocolGuid,\r | |
499 | UnixDevice->DevicePath,\r | |
500 | &gEfiUnixIoProtocolGuid,\r | |
501 | &UnixDevice->UnixIo,\r | |
502 | NULL\r | |
503 | );\r | |
504 | if (EFI_ERROR (Status)) {\r | |
505 | FreeUnicodeStringTable (UnixDevice->ControllerNameTable);\r | |
506 | gBS->FreePool (UnixDevice);\r | |
507 | } else {\r | |
508 | //\r | |
509 | // Open For Child Device\r | |
510 | //\r | |
511 | Status = gBS->OpenProtocol (\r | |
512 | ControllerHandle,\r | |
513 | &gEfiUnixThunkProtocolGuid,\r | |
514 | (VOID **)&UnixThunk,\r | |
515 | This->DriverBindingHandle,\r | |
516 | UnixDevice->Handle,\r | |
517 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
518 | );\r | |
519 | if (!EFI_ERROR (Status)) {\r | |
520 | InstallStatus = EFI_SUCCESS;\r | |
521 | }\r | |
522 | }\r | |
523 | }\r | |
524 | \r | |
525 | //\r | |
526 | // Parse Next sub string. This will point to '\0' if we are at the end.\r | |
527 | //\r | |
528 | Count++;\r | |
529 | StartString = SubString;\r | |
530 | }\r | |
531 | \r | |
532 | gBS->FreePool (TempStr);\r | |
533 | }\r | |
534 | \r | |
535 | return EFI_SUCCESS;\r | |
536 | }\r | |
537 | \r | |
538 | \r | |
539 | EFI_STATUS\r | |
540 | EFIAPI\r | |
541 | UnixBusDriverBindingStop (\r | |
542 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
543 | IN EFI_HANDLE ControllerHandle,\r | |
544 | IN UINTN NumberOfChildren,\r | |
545 | IN EFI_HANDLE *ChildHandleBuffer\r | |
546 | )\r | |
547 | /*++\r | |
548 | \r | |
549 | Routine Description:\r | |
550 | \r | |
551 | Arguments:\r | |
552 | \r | |
553 | Returns:\r | |
554 | \r | |
555 | None\r | |
556 | \r | |
557 | --*/\r | |
804405e7 | 558 | {\r |
559 | EFI_STATUS Status;\r | |
560 | UINTN Index;\r | |
561 | BOOLEAN AllChildrenStopped;\r | |
562 | EFI_UNIX_IO_PROTOCOL *UnixIo;\r | |
563 | UNIX_BUS_DEVICE *UnixBusDevice;\r | |
564 | UNIX_IO_DEVICE *UnixDevice;\r | |
565 | EFI_UNIX_THUNK_PROTOCOL *UnixThunk;\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 | &gUnixBusDriverGuid,\r | |
579 | (VOID **)&UnixBusDevice,\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 | &gUnixBusDriverGuid,\r | |
591 | UnixBusDevice,\r | |
592 | NULL\r | |
593 | );\r | |
594 | \r | |
595 | FreeUnicodeStringTable (UnixBusDevice->ControllerNameTable);\r | |
596 | \r | |
597 | gBS->FreePool (UnixBusDevice);\r | |
598 | \r | |
599 | gBS->CloseProtocol (\r | |
600 | ControllerHandle,\r | |
601 | &gEfiUnixThunkProtocolGuid,\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 | &gEfiUnixIoProtocolGuid,\r | |
622 | (VOID **)&UnixIo,\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 | UnixDevice = UNIX_IO_DEVICE_FROM_THIS (UnixIo);\r | |
630 | \r | |
631 | Status = gBS->CloseProtocol (\r | |
632 | ControllerHandle,\r | |
633 | &gEfiUnixThunkProtocolGuid,\r | |
634 | This->DriverBindingHandle,\r | |
635 | UnixDevice->Handle\r | |
636 | );\r | |
637 | \r | |
638 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
639 | UnixDevice->Handle,\r | |
640 | &gEfiDevicePathProtocolGuid,\r | |
641 | UnixDevice->DevicePath,\r | |
642 | &gEfiUnixIoProtocolGuid,\r | |
643 | &UnixDevice->UnixIo,\r | |
644 | NULL\r | |
645 | );\r | |
646 | \r | |
647 | if (EFI_ERROR (Status)) {\r | |
648 | gBS->OpenProtocol (\r | |
649 | ControllerHandle,\r | |
650 | &gEfiUnixThunkProtocolGuid,\r | |
651 | (VOID **) &UnixThunk,\r | |
652 | This->DriverBindingHandle,\r | |
653 | UnixDevice->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 (UnixDevice->ControllerNameTable);\r | |
661 | gBS->FreePool (UnixDevice);\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 | UnixBusCreateDevicePath (\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 | UNIX_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 (UNIX_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 |