fb0b259e |
1 | /** @file\r |
dfe687ca |
2 | Console Platform DXE Driver, install Console Device Guids and update Console\r |
9359e53f |
3 | Environment Variables.\r |
95276127 |
4 | \r |
9359e53f |
5 | Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r |
95276127 |
6 | All rights reserved. This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r |
8 | which accompanies this distribution. The full text of the license may be found at\r |
9 | http://opensource.org/licenses/bsd-license.php\r |
10 | \r |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r |
13 | \r |
fb0b259e |
14 | **/\r |
95276127 |
15 | \r |
0ad02bbd |
16 | #include "ConPlatform.h"\r |
95276127 |
17 | \r |
95276127 |
18 | \r |
19 | EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding = {\r |
20 | ConPlatformTextInDriverBindingSupported,\r |
21 | ConPlatformTextInDriverBindingStart,\r |
22 | ConPlatformTextInDriverBindingStop,\r |
23 | 0xa,\r |
24 | NULL,\r |
25 | NULL\r |
26 | };\r |
27 | \r |
28 | EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextOutDriverBinding = {\r |
29 | ConPlatformTextOutDriverBindingSupported,\r |
30 | ConPlatformTextOutDriverBindingStart,\r |
31 | ConPlatformTextOutDriverBindingStop,\r |
32 | 0xa,\r |
33 | NULL,\r |
34 | NULL\r |
35 | };\r |
36 | \r |
37 | /**\r |
c5ed97f6 |
38 | Entrypoint of this module.\r |
39 | \r |
40 | This function is the entrypoint of this module. It installs Driver Binding\r |
41 | Protocols together with Component Name Protocols.\r |
95276127 |
42 | \r |
7b9ff698 |
43 | @param ImageHandle The firmware allocated handle for the EFI image.\r |
44 | @param SystemTable A pointer to the EFI System Table.\r |
c62a593c |
45 | \r |
95276127 |
46 | @retval EFI_SUCCESS The entry point is executed successfully.\r |
95276127 |
47 | \r |
48 | **/\r |
49 | EFI_STATUS\r |
50 | EFIAPI\r |
51 | InitializeConPlatform(\r |
52 | IN EFI_HANDLE ImageHandle,\r |
53 | IN EFI_SYSTEM_TABLE *SystemTable\r |
54 | )\r |
55 | {\r |
56 | EFI_STATUS Status;\r |
57 | \r |
5bca971e |
58 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
95276127 |
59 | ImageHandle,\r |
60 | SystemTable,\r |
61 | &gConPlatformTextInDriverBinding,\r |
62 | ImageHandle,\r |
63 | &gConPlatformComponentName,\r |
5bca971e |
64 | &gConPlatformComponentName2\r |
95276127 |
65 | );\r |
66 | ASSERT_EFI_ERROR (Status);\r |
67 | \r |
5bca971e |
68 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
95276127 |
69 | ImageHandle,\r |
70 | SystemTable,\r |
71 | &gConPlatformTextOutDriverBinding,\r |
72 | NULL,\r |
73 | &gConPlatformComponentName,\r |
5bca971e |
74 | &gConPlatformComponentName2\r |
95276127 |
75 | );\r |
76 | ASSERT_EFI_ERROR (Status);\r |
77 | \r |
c5ed97f6 |
78 | return EFI_SUCCESS;\r |
95276127 |
79 | }\r |
80 | \r |
81 | \r |
9359e53f |
82 | /**\r |
c5ed97f6 |
83 | Test to see if EFI_SIMPLE_TEXT_INPUT_PROTOCOL is supported on ControllerHandle. \r |
9359e53f |
84 | \r |
85 | @param This Protocol instance pointer.\r |
86 | @param ControllerHandle Handle of device to test.\r |
87 | @param RemainingDevicePath Optional parameter use to pick a specific child\r |
88 | device to start.\r |
89 | \r |
7b9ff698 |
90 | @retval EFI_SUCCESS This driver supports this device.\r |
91 | @retval other This driver does not support this device.\r |
9359e53f |
92 | \r |
93 | **/\r |
95276127 |
94 | EFI_STATUS\r |
95 | EFIAPI\r |
96 | ConPlatformTextInDriverBindingSupported (\r |
97 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
98 | IN EFI_HANDLE ControllerHandle,\r |
c5ed97f6 |
99 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r |
95276127 |
100 | )\r |
95276127 |
101 | {\r |
102 | return ConPlatformDriverBindingSupported (\r |
c5ed97f6 |
103 | This,\r |
104 | ControllerHandle,\r |
105 | &gEfiSimpleTextInProtocolGuid\r |
106 | );\r |
95276127 |
107 | }\r |
108 | \r |
9359e53f |
109 | \r |
110 | /**\r |
c5ed97f6 |
111 | Test to see if EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL is supported on ControllerHandle. \r |
9359e53f |
112 | \r |
113 | @param This Protocol instance pointer.\r |
114 | @param ControllerHandle Handle of device to test.\r |
115 | @param RemainingDevicePath Optional parameter use to pick a specific child\r |
116 | device to start.\r |
117 | \r |
7b9ff698 |
118 | @retval EFI_SUCCESS This driver supports this device.\r |
119 | @retval other This driver does not support this device.\r |
9359e53f |
120 | \r |
121 | **/\r |
95276127 |
122 | EFI_STATUS\r |
123 | EFIAPI\r |
124 | ConPlatformTextOutDriverBindingSupported (\r |
125 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
126 | IN EFI_HANDLE ControllerHandle,\r |
c5ed97f6 |
127 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r |
95276127 |
128 | )\r |
95276127 |
129 | {\r |
130 | return ConPlatformDriverBindingSupported (\r |
c5ed97f6 |
131 | This,\r |
132 | ControllerHandle,\r |
133 | &gEfiSimpleTextOutProtocolGuid\r |
134 | );\r |
95276127 |
135 | }\r |
136 | \r |
9359e53f |
137 | \r |
138 | /**\r |
c5ed97f6 |
139 | Test to see if the specified protocol is supported on ControllerHandle. \r |
9359e53f |
140 | \r |
141 | @param This Protocol instance pointer.\r |
142 | @param ControllerHandle Handle of device to test.\r |
9359e53f |
143 | @param ProtocolGuid The specfic protocol.\r |
144 | \r |
7b9ff698 |
145 | @retval EFI_SUCCESS This driver supports this device.\r |
146 | @retval other This driver does not support this device.\r |
9359e53f |
147 | \r |
148 | **/\r |
95276127 |
149 | EFI_STATUS\r |
150 | ConPlatformDriverBindingSupported (\r |
151 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
152 | IN EFI_HANDLE ControllerHandle,\r |
95276127 |
153 | IN EFI_GUID *ProtocolGuid\r |
154 | )\r |
95276127 |
155 | {\r |
156 | EFI_STATUS Status;\r |
157 | VOID *Interface;\r |
158 | \r |
159 | //\r |
7b9ff698 |
160 | // Test to see if this is a physical device by checking if\r |
161 | // it has a Device Path Protocol.\r |
95276127 |
162 | //\r |
163 | Status = gBS->OpenProtocol (\r |
164 | ControllerHandle,\r |
165 | &gEfiDevicePathProtocolGuid,\r |
166 | NULL,\r |
167 | This->DriverBindingHandle,\r |
168 | ControllerHandle,\r |
169 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r |
170 | );\r |
171 | if (EFI_ERROR (Status)) {\r |
172 | return Status;\r |
173 | }\r |
174 | //\r |
7b9ff698 |
175 | // Test to see if this device supports the specified Protocol.\r |
95276127 |
176 | //\r |
177 | Status = gBS->OpenProtocol (\r |
178 | ControllerHandle,\r |
179 | ProtocolGuid,\r |
180 | (VOID **) &Interface,\r |
181 | This->DriverBindingHandle,\r |
182 | ControllerHandle,\r |
183 | EFI_OPEN_PROTOCOL_BY_DRIVER\r |
184 | );\r |
185 | if (EFI_ERROR (Status)) {\r |
186 | return Status;\r |
187 | }\r |
188 | \r |
189 | gBS->CloseProtocol (\r |
c5ed97f6 |
190 | ControllerHandle,\r |
191 | ProtocolGuid,\r |
192 | This->DriverBindingHandle,\r |
193 | ControllerHandle\r |
194 | );\r |
95276127 |
195 | \r |
196 | return EFI_SUCCESS;\r |
197 | }\r |
198 | \r |
9359e53f |
199 | /**\r |
c5ed97f6 |
200 | Start this driver on the device for console input.\r |
201 | \r |
202 | Start this driver on ControllerHandle by opening Simple Text Input Protocol,\r |
24248368 |
203 | reading Device Path, and installing Console In Devcice GUID on ControllerHandle.\r |
9359e53f |
204 | \r |
205 | If this devcie is not one hot-plug devce, append its device path into the \r |
206 | console environment variables ConInDev.\r |
207 | \r |
208 | @param This Protocol instance pointer.\r |
209 | @param ControllerHandle Handle of device to bind driver to\r |
210 | @param RemainingDevicePath Optional parameter use to pick a specific child\r |
211 | device to start.\r |
212 | \r |
213 | @retval EFI_SUCCESS This driver is added to ControllerHandle\r |
214 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r |
415df2a3 |
215 | @retval other This driver does not support this device.\r |
9359e53f |
216 | \r |
217 | **/\r |
95276127 |
218 | EFI_STATUS\r |
219 | EFIAPI\r |
220 | ConPlatformTextInDriverBindingStart (\r |
221 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
222 | IN EFI_HANDLE ControllerHandle,\r |
223 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r |
224 | )\r |
95276127 |
225 | {\r |
c5ed97f6 |
226 | EFI_STATUS Status;\r |
227 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r |
95276127 |
228 | EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;\r |
229 | \r |
230 | //\r |
231 | // Get the Device Path Protocol so the environment variables can be updated\r |
232 | //\r |
233 | Status = gBS->OpenProtocol (\r |
234 | ControllerHandle,\r |
235 | &gEfiDevicePathProtocolGuid,\r |
236 | (VOID **) &DevicePath,\r |
237 | This->DriverBindingHandle,\r |
238 | ControllerHandle,\r |
239 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r |
240 | );\r |
241 | if (EFI_ERROR (Status)) {\r |
242 | return Status;\r |
243 | }\r |
244 | //\r |
c5ed97f6 |
245 | // Open the Simple Text Input Protocol BY_DRIVER\r |
95276127 |
246 | //\r |
247 | Status = gBS->OpenProtocol (\r |
248 | ControllerHandle,\r |
249 | &gEfiSimpleTextInProtocolGuid,\r |
250 | (VOID **) &TextIn,\r |
251 | This->DriverBindingHandle,\r |
252 | ControllerHandle,\r |
253 | EFI_OPEN_PROTOCOL_BY_DRIVER\r |
254 | );\r |
255 | if (EFI_ERROR (Status)) {\r |
256 | return Status;\r |
257 | }\r |
258 | //\r |
259 | // Check the device handle, if it is a hot plug device,\r |
260 | // do not put the device path into ConInDev, and install\r |
261 | // gEfiConsoleInDeviceGuid to the device handle directly.\r |
262 | // The policy is, make hot plug device plug in and play immediately.\r |
263 | //\r |
ea1ac7a0 |
264 | if (IsHotPlugDevice (DevicePath)) {\r |
95276127 |
265 | gBS->InstallMultipleProtocolInterfaces (\r |
c5ed97f6 |
266 | &ControllerHandle,\r |
267 | &gEfiConsoleInDeviceGuid,\r |
268 | NULL,\r |
269 | NULL\r |
270 | );\r |
95276127 |
271 | } else {\r |
272 | //\r |
c5ed97f6 |
273 | // If it is not a hot-plug device, append the device path to the\r |
274 | // ConInDev environment variable\r |
95276127 |
275 | //\r |
276 | ConPlatformUpdateDeviceVariable (\r |
ff37790d |
277 | L"ConInDev",\r |
95276127 |
278 | DevicePath,\r |
279 | APPEND\r |
280 | );\r |
281 | \r |
282 | //\r |
c5ed97f6 |
283 | // If the device path is successfully added to the ConIn environment variable,\r |
95276127 |
284 | // then install EfiConsoleInDeviceGuid onto ControllerHandle\r |
285 | //\r |
286 | Status = ConPlatformUpdateDeviceVariable (\r |
c5ed97f6 |
287 | L"ConIn",\r |
288 | DevicePath,\r |
289 | CHECK\r |
290 | );\r |
95276127 |
291 | \r |
292 | if (!EFI_ERROR (Status)) {\r |
293 | gBS->InstallMultipleProtocolInterfaces (\r |
c5ed97f6 |
294 | &ControllerHandle,\r |
295 | &gEfiConsoleInDeviceGuid,\r |
296 | NULL,\r |
297 | NULL\r |
298 | );\r |
95276127 |
299 | } else {\r |
300 | gBS->CloseProtocol (\r |
c5ed97f6 |
301 | ControllerHandle,\r |
302 | &gEfiSimpleTextInProtocolGuid,\r |
303 | This->DriverBindingHandle,\r |
304 | ControllerHandle\r |
305 | );\r |
95276127 |
306 | }\r |
307 | }\r |
308 | \r |
309 | return EFI_SUCCESS;\r |
310 | }\r |
311 | \r |
9359e53f |
312 | /**\r |
c5ed97f6 |
313 | Start this driver on the device for console output and stardard error output.\r |
314 | \r |
315 | Start this driver on ControllerHandle by opening Simple Text Output Protocol,\r |
24248368 |
316 | reading Device Path, and installing Console Out Devcic GUID, Standard Error\r |
9359e53f |
317 | Device GUID on ControllerHandle.\r |
318 | \r |
319 | If this devcie is not one hot-plug devce, append its device path into the \r |
7772b176 |
320 | console environment variables ConOutDev, ErrOutDev.\r |
9359e53f |
321 | \r |
322 | @param This Protocol instance pointer.\r |
323 | @param ControllerHandle Handle of device to bind driver to\r |
324 | @param RemainingDevicePath Optional parameter use to pick a specific child\r |
325 | device to start.\r |
326 | \r |
327 | @retval EFI_SUCCESS This driver is added to ControllerHandle\r |
328 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r |
329 | @retval other This driver does not support this device\r |
330 | \r |
331 | **/\r |
95276127 |
332 | EFI_STATUS\r |
333 | EFIAPI\r |
334 | ConPlatformTextOutDriverBindingStart (\r |
335 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
336 | IN EFI_HANDLE ControllerHandle,\r |
337 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r |
338 | )\r |
95276127 |
339 | {\r |
c5ed97f6 |
340 | EFI_STATUS Status;\r |
341 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r |
95276127 |
342 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;\r |
c5ed97f6 |
343 | BOOLEAN NeedClose;\r |
95276127 |
344 | \r |
345 | NeedClose = TRUE;\r |
346 | \r |
347 | //\r |
348 | // Get the Device Path Protocol so the environment variables can be updated\r |
349 | //\r |
350 | Status = gBS->OpenProtocol (\r |
351 | ControllerHandle,\r |
352 | &gEfiDevicePathProtocolGuid,\r |
353 | (VOID **) &DevicePath,\r |
354 | This->DriverBindingHandle,\r |
355 | ControllerHandle,\r |
356 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r |
357 | );\r |
358 | if (EFI_ERROR (Status)) {\r |
359 | return Status;\r |
360 | }\r |
361 | //\r |
362 | // Open the Simple Text Output Protocol BY_DRIVER\r |
363 | //\r |
364 | Status = gBS->OpenProtocol (\r |
365 | ControllerHandle,\r |
366 | &gEfiSimpleTextOutProtocolGuid,\r |
367 | (VOID **) &TextOut,\r |
368 | This->DriverBindingHandle,\r |
369 | ControllerHandle,\r |
370 | EFI_OPEN_PROTOCOL_BY_DRIVER\r |
371 | );\r |
372 | if (EFI_ERROR (Status)) {\r |
373 | return Status;\r |
374 | }\r |
375 | //\r |
376 | // Check the device handle, if it is a hot plug device,\r |
7772b176 |
377 | // do not put the device path into ConOutDev and ErrOutDev,\r |
95276127 |
378 | // and install gEfiConsoleOutDeviceGuid to the device handle directly.\r |
379 | // The policy is, make hot plug device plug in and play immediately.\r |
380 | //\r |
ea1ac7a0 |
381 | if (IsHotPlugDevice (DevicePath)) {\r |
95276127 |
382 | gBS->InstallMultipleProtocolInterfaces (\r |
c5ed97f6 |
383 | &ControllerHandle,\r |
384 | &gEfiConsoleOutDeviceGuid,\r |
385 | NULL,\r |
386 | NULL\r |
387 | );\r |
95276127 |
388 | } else {\r |
389 | //\r |
c5ed97f6 |
390 | // If it is not a hot-plug device, first append the device path to the\r |
391 | // ConOutDev environment variable\r |
95276127 |
392 | //\r |
393 | ConPlatformUpdateDeviceVariable (\r |
ff37790d |
394 | L"ConOutDev",\r |
95276127 |
395 | DevicePath,\r |
396 | APPEND\r |
397 | );\r |
398 | //\r |
7772b176 |
399 | // Then append the device path to the ErrOutDev environment variable\r |
95276127 |
400 | //\r |
401 | ConPlatformUpdateDeviceVariable (\r |
ff37790d |
402 | L"ErrOutDev",\r |
95276127 |
403 | DevicePath,\r |
404 | APPEND\r |
405 | );\r |
406 | \r |
407 | //\r |
c5ed97f6 |
408 | // If the device path is successfully added to the ConOut environment variable,\r |
95276127 |
409 | // then install EfiConsoleOutDeviceGuid onto ControllerHandle\r |
410 | //\r |
411 | Status = ConPlatformUpdateDeviceVariable (\r |
c5ed97f6 |
412 | L"ConOut",\r |
413 | DevicePath,\r |
414 | CHECK\r |
415 | );\r |
95276127 |
416 | \r |
417 | if (!EFI_ERROR (Status)) {\r |
418 | NeedClose = FALSE;\r |
419 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
420 | &ControllerHandle,\r |
421 | &gEfiConsoleOutDeviceGuid,\r |
422 | NULL,\r |
423 | NULL\r |
424 | );\r |
425 | }\r |
426 | //\r |
7772b176 |
427 | // If the device path is successfully added to the ErrOut environment variable,\r |
95276127 |
428 | // then install EfiStandardErrorDeviceGuid onto ControllerHandle\r |
429 | //\r |
430 | Status = ConPlatformUpdateDeviceVariable (\r |
c5ed97f6 |
431 | L"ErrOut",\r |
432 | DevicePath,\r |
433 | CHECK\r |
434 | );\r |
95276127 |
435 | if (!EFI_ERROR (Status)) {\r |
436 | NeedClose = FALSE;\r |
437 | gBS->InstallMultipleProtocolInterfaces (\r |
c5ed97f6 |
438 | &ControllerHandle,\r |
439 | &gEfiStandardErrorDeviceGuid,\r |
440 | NULL,\r |
441 | NULL\r |
442 | );\r |
95276127 |
443 | }\r |
444 | \r |
445 | if (NeedClose) {\r |
446 | gBS->CloseProtocol (\r |
c5ed97f6 |
447 | ControllerHandle,\r |
448 | &gEfiSimpleTextOutProtocolGuid,\r |
449 | This->DriverBindingHandle,\r |
450 | ControllerHandle\r |
451 | );\r |
95276127 |
452 | }\r |
453 | }\r |
454 | \r |
455 | return EFI_SUCCESS;\r |
456 | }\r |
457 | \r |
9359e53f |
458 | /**\r |
24248368 |
459 | Stop this driver on ControllerHandle by removing Console In Devcice GUID \r |
c5ed97f6 |
460 | and closing the Simple Text Input protocol on ControllerHandle.\r |
9359e53f |
461 | \r |
462 | @param This Protocol instance pointer.\r |
463 | @param ControllerHandle Handle of device to stop driver on\r |
464 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r |
465 | children is zero stop the entire bus driver.\r |
466 | @param ChildHandleBuffer List of Child Handles to Stop.\r |
467 | \r |
468 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r |
469 | @retval other This driver was not removed from this device\r |
470 | \r |
471 | **/\r |
95276127 |
472 | EFI_STATUS\r |
473 | EFIAPI\r |
474 | ConPlatformTextInDriverBindingStop (\r |
475 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
476 | IN EFI_HANDLE ControllerHandle,\r |
477 | IN UINTN NumberOfChildren,\r |
478 | IN EFI_HANDLE *ChildHandleBuffer\r |
479 | )\r |
95276127 |
480 | {\r |
481 | EFI_STATUS Status;\r |
482 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r |
483 | \r |
ea1ac7a0 |
484 | //\r |
485 | // Get the Device Path Protocol firstly\r |
486 | //\r |
487 | Status = gBS->OpenProtocol (\r |
488 | ControllerHandle,\r |
489 | &gEfiDevicePathProtocolGuid,\r |
490 | (VOID **) &DevicePath,\r |
491 | This->DriverBindingHandle,\r |
492 | ControllerHandle,\r |
493 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r |
494 | );\r |
495 | \r |
496 | if (EFI_ERROR (Status)) {\r |
497 | return Status;\r |
498 | }\r |
499 | \r |
95276127 |
500 | //\r |
c5ed97f6 |
501 | // If it is not a hot-plug device, first delete it from the ConInDev variable.\r |
95276127 |
502 | //\r |
ea1ac7a0 |
503 | if (!IsHotPlugDevice (DevicePath)) {\r |
504 | //\r |
505 | // Remove DevicePath from ConInDev\r |
95276127 |
506 | //\r |
ea1ac7a0 |
507 | ConPlatformUpdateDeviceVariable (\r |
508 | L"ConInDev",\r |
509 | DevicePath,\r |
510 | DELETE\r |
511 | );\r |
95276127 |
512 | }\r |
ea1ac7a0 |
513 | \r |
95276127 |
514 | //\r |
515 | // Uninstall the Console Device GUIDs from Controller Handle\r |
516 | //\r |
517 | ConPlatformUnInstallProtocol (\r |
518 | This,\r |
519 | ControllerHandle,\r |
520 | &gEfiConsoleInDeviceGuid\r |
521 | );\r |
522 | \r |
523 | //\r |
c5ed97f6 |
524 | // Close the Simple Text Input Protocol\r |
95276127 |
525 | //\r |
526 | gBS->CloseProtocol (\r |
527 | ControllerHandle,\r |
528 | &gEfiSimpleTextInProtocolGuid,\r |
529 | This->DriverBindingHandle,\r |
530 | ControllerHandle\r |
531 | );\r |
532 | \r |
533 | return EFI_SUCCESS;\r |
534 | }\r |
535 | \r |
9359e53f |
536 | \r |
537 | /**\r |
24248368 |
538 | Stop this driver on ControllerHandle by removing Console Out Devcice GUID \r |
c5ed97f6 |
539 | and closing the Simple Text Output protocol on ControllerHandle.\r |
9359e53f |
540 | \r |
541 | @param This Protocol instance pointer.\r |
542 | @param ControllerHandle Handle of device to stop driver on\r |
543 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r |
544 | children is zero stop the entire bus driver.\r |
545 | @param ChildHandleBuffer List of Child Handles to Stop.\r |
546 | \r |
547 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r |
548 | @retval other This driver was not removed from this device\r |
549 | \r |
550 | **/\r |
95276127 |
551 | EFI_STATUS\r |
552 | EFIAPI\r |
553 | ConPlatformTextOutDriverBindingStop (\r |
554 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
555 | IN EFI_HANDLE ControllerHandle,\r |
556 | IN UINTN NumberOfChildren,\r |
557 | IN EFI_HANDLE *ChildHandleBuffer\r |
558 | )\r |
95276127 |
559 | {\r |
560 | EFI_STATUS Status;\r |
561 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r |
562 | \r |
ea1ac7a0 |
563 | //\r |
564 | // Get the Device Path Protocol firstly\r |
565 | //\r |
566 | Status = gBS->OpenProtocol (\r |
567 | ControllerHandle,\r |
568 | &gEfiDevicePathProtocolGuid,\r |
569 | (VOID **) &DevicePath,\r |
570 | This->DriverBindingHandle,\r |
571 | ControllerHandle,\r |
572 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r |
573 | );\r |
574 | \r |
575 | if (EFI_ERROR (Status)) {\r |
576 | return Status;\r |
577 | }\r |
578 | \r |
95276127 |
579 | //\r |
7772b176 |
580 | // If it is not a hot-plug device, first delete it from the ConOutDev and ErrOutDev variable.\r |
95276127 |
581 | //\r |
ea1ac7a0 |
582 | if (!IsHotPlugDevice (DevicePath)) {\r |
95276127 |
583 | //\r |
ea1ac7a0 |
584 | // Remove DevicePath from ConOutDev, and ErrOutDev\r |
95276127 |
585 | //\r |
ea1ac7a0 |
586 | ConPlatformUpdateDeviceVariable (\r |
587 | L"ConOutDev",\r |
588 | DevicePath,\r |
589 | DELETE\r |
590 | );\r |
591 | ConPlatformUpdateDeviceVariable (\r |
592 | L"ErrOutDev",\r |
593 | DevicePath,\r |
594 | DELETE\r |
595 | );\r |
95276127 |
596 | }\r |
ea1ac7a0 |
597 | \r |
95276127 |
598 | //\r |
599 | // Uninstall the Console Device GUIDs from Controller Handle\r |
600 | //\r |
601 | ConPlatformUnInstallProtocol (\r |
602 | This,\r |
603 | ControllerHandle,\r |
604 | &gEfiConsoleOutDeviceGuid\r |
605 | );\r |
606 | \r |
607 | ConPlatformUnInstallProtocol (\r |
608 | This,\r |
609 | ControllerHandle,\r |
610 | &gEfiStandardErrorDeviceGuid\r |
611 | );\r |
612 | \r |
613 | //\r |
614 | // Close the Simple Text Output Protocol\r |
615 | //\r |
616 | gBS->CloseProtocol (\r |
617 | ControllerHandle,\r |
618 | &gEfiSimpleTextOutProtocolGuid,\r |
619 | This->DriverBindingHandle,\r |
620 | ControllerHandle\r |
621 | );\r |
622 | \r |
623 | return EFI_SUCCESS;\r |
624 | }\r |
625 | \r |
626 | \r |
9359e53f |
627 | /**\r |
7b9ff698 |
628 | Uninstall the specified protocol.\r |
9359e53f |
629 | \r |
630 | @param This Protocol instance pointer.\r |
7b9ff698 |
631 | @param Handle Handle of device to uninstall protocol on.\r |
632 | @param ProtocolGuid The specified protocol need to be uninstalled.\r |
9359e53f |
633 | \r |
9359e53f |
634 | **/\r |
95276127 |
635 | VOID\r |
636 | ConPlatformUnInstallProtocol (\r |
637 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
638 | IN EFI_HANDLE Handle,\r |
639 | IN EFI_GUID *ProtocolGuid\r |
640 | )\r |
641 | {\r |
642 | EFI_STATUS Status;\r |
643 | \r |
644 | Status = gBS->OpenProtocol (\r |
645 | Handle,\r |
646 | ProtocolGuid,\r |
647 | NULL,\r |
648 | This->DriverBindingHandle,\r |
649 | Handle,\r |
650 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r |
651 | );\r |
652 | \r |
653 | if (!EFI_ERROR (Status)) {\r |
654 | gBS->UninstallMultipleProtocolInterfaces (\r |
c5ed97f6 |
655 | Handle,\r |
656 | ProtocolGuid,\r |
657 | NULL,\r |
658 | NULL\r |
659 | );\r |
95276127 |
660 | }\r |
661 | \r |
662 | return ;\r |
663 | }\r |
664 | \r |
9359e53f |
665 | /**\r |
7772b176 |
666 | Get the necessary size of buffer and read the variable.\r |
c5ed97f6 |
667 | \r |
668 | First get the necessary size of buffer. Then read the\r |
669 | EFI variable (Name) and return a dynamically allocated\r |
670 | buffer. On failure return NULL.\r |
95276127 |
671 | \r |
9359e53f |
672 | @param Name String part of EFI variable name\r |
95276127 |
673 | \r |
9359e53f |
674 | @return Dynamically allocated memory that contains a copy of the EFI variable.\r |
7b9ff698 |
675 | Caller is repsoncible freeing the buffer. Return NULL means Variable \r |
676 | was not read.\r |
95276127 |
677 | \r |
9359e53f |
678 | **/\r |
679 | VOID *\r |
680 | ConPlatformGetVariable (\r |
681 | IN CHAR16 *Name\r |
682 | )\r |
95276127 |
683 | {\r |
684 | EFI_STATUS Status;\r |
685 | VOID *Buffer;\r |
686 | UINTN BufferSize;\r |
687 | \r |
688 | BufferSize = 0;\r |
689 | Buffer = NULL;\r |
690 | \r |
691 | //\r |
c5ed97f6 |
692 | // Test to see if the variable exists. If it doesn't, return NULL.\r |
95276127 |
693 | //\r |
694 | Status = gRT->GetVariable (\r |
695 | Name,\r |
696 | &gEfiGlobalVariableGuid,\r |
697 | NULL,\r |
698 | &BufferSize,\r |
699 | Buffer\r |
700 | );\r |
701 | \r |
702 | if (Status == EFI_BUFFER_TOO_SMALL) {\r |
703 | //\r |
704 | // Allocate the buffer to return\r |
705 | //\r |
706 | Buffer = AllocatePool (BufferSize);\r |
707 | if (Buffer == NULL) {\r |
708 | return NULL;\r |
709 | }\r |
710 | //\r |
711 | // Read variable into the allocated buffer.\r |
712 | //\r |
713 | Status = gRT->GetVariable (\r |
714 | Name,\r |
715 | &gEfiGlobalVariableGuid,\r |
716 | NULL,\r |
717 | &BufferSize,\r |
718 | Buffer\r |
719 | );\r |
720 | if (EFI_ERROR (Status)) {\r |
721 | FreePool (Buffer);\r |
7b9ff698 |
722 | //\r |
723 | // To make sure Buffer is NULL if any error occurs.\r |
724 | //\r |
95276127 |
725 | Buffer = NULL;\r |
726 | }\r |
727 | }\r |
728 | \r |
729 | return Buffer;\r |
730 | }\r |
731 | \r |
9359e53f |
732 | /**\r |
95276127 |
733 | Function compares a device path data structure to that of all the nodes of a\r |
734 | second device path instance.\r |
735 | \r |
9359e53f |
736 | @param Multi A pointer to a multi-instance device path data structure.\r |
737 | @param Single A pointer to a single-instance device path data structure.\r |
738 | @param NewDevicePath If Delete is TRUE, this parameter must not be null, and it\r |
739 | points to the remaining device path data structure.\r |
740 | (remaining device path = Multi - Single.)\r |
741 | @param Delete If TRUE, means removing Single from Multi.\r |
742 | If FALSE, the routine just check whether Single matches\r |
743 | with any instance in Multi.\r |
95276127 |
744 | \r |
c5ed97f6 |
745 | @retval EFI_SUCCESS If the Single is contained within Multi.\r |
746 | @retval EFI_NOT_FOUND If the Single is not contained within Multi.\r |
747 | @retval EFI_INVALID_PARAMETER Multi is NULL.\r |
748 | @retval EFI_INVALID_PARAMETER Single is NULL.\r |
749 | @retval EFI_INVALID_PARAMETER NewDevicePath is NULL when Delete is TRUE.\r |
95276127 |
750 | \r |
9359e53f |
751 | **/\r |
752 | EFI_STATUS\r |
753 | ConPlatformMatchDevicePaths (\r |
754 | IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r |
755 | IN EFI_DEVICE_PATH_PROTOCOL *Single,\r |
7b9ff698 |
756 | OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath OPTIONAL,\r |
9359e53f |
757 | IN BOOLEAN Delete\r |
758 | )\r |
95276127 |
759 | {\r |
760 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r |
7b9ff698 |
761 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath1;\r |
762 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath2;\r |
95276127 |
763 | EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r |
764 | UINTN Size;\r |
765 | \r |
766 | //\r |
767 | // The passed in DevicePath should not be NULL\r |
768 | //\r |
9359e53f |
769 | if ((Multi == NULL) || (Single == NULL)) {\r |
c5ed97f6 |
770 | return EFI_INVALID_PARAMETER;\r |
95276127 |
771 | }\r |
7b9ff698 |
772 | \r |
95276127 |
773 | //\r |
7b9ff698 |
774 | // If performing Delete operation, the NewDevicePath must not be NULL.\r |
95276127 |
775 | //\r |
7b9ff698 |
776 | if (Delete) {\r |
c5ed97f6 |
777 | if (NewDevicePath == NULL) {\r |
778 | return EFI_INVALID_PARAMETER;\r |
779 | }\r |
7b9ff698 |
780 | }\r |
781 | \r |
782 | TempDevicePath1 = NULL;\r |
95276127 |
783 | \r |
784 | DevicePath = Multi;\r |
785 | DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r |
786 | \r |
787 | //\r |
7b9ff698 |
788 | // Search for the match of 'Single' in 'Multi'\r |
95276127 |
789 | //\r |
9359e53f |
790 | while (DevicePathInst != NULL) {\r |
95276127 |
791 | if (CompareMem (Single, DevicePathInst, Size) == 0) {\r |
792 | if (!Delete) {\r |
7b9ff698 |
793 | //\r |
794 | // If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.\r |
795 | //\r |
95276127 |
796 | FreePool (DevicePathInst);\r |
797 | return EFI_SUCCESS;\r |
798 | }\r |
799 | } else {\r |
800 | if (Delete) {\r |
7b9ff698 |
801 | //\r |
c5ed97f6 |
802 | // If the node of Multi does not match Single, then added it back to the result.\r |
803 | // That is, the node matching Single will be dropped and deleted from result.\r |
7b9ff698 |
804 | //\r |
805 | TempDevicePath2 = AppendDevicePathInstance (\r |
806 | TempDevicePath1,\r |
95276127 |
807 | DevicePathInst\r |
808 | );\r |
676df92c |
809 | if (TempDevicePath1 != NULL) {\r |
810 | FreePool (TempDevicePath1);\r |
811 | }\r |
7b9ff698 |
812 | TempDevicePath1 = TempDevicePath2;\r |
95276127 |
813 | }\r |
814 | }\r |
815 | \r |
816 | FreePool (DevicePathInst);\r |
817 | DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r |
818 | }\r |
819 | \r |
820 | if (Delete) {\r |
7b9ff698 |
821 | //\r |
c5ed97f6 |
822 | // Return the new device path data structure with specified node deleted.\r |
7b9ff698 |
823 | //\r |
824 | *NewDevicePath = TempDevicePath1;\r |
95276127 |
825 | return EFI_SUCCESS;\r |
826 | }\r |
827 | \r |
828 | return EFI_NOT_FOUND;\r |
829 | }\r |
830 | \r |
9359e53f |
831 | /**\r |
7b9ff698 |
832 | Update console environment variables. \r |
9359e53f |
833 | \r |
834 | @param VariableName Console environment variables, ConOutDev, ConInDev\r |
7772b176 |
835 | ErrOutDev, ConIn ,ConOut or ErrOut.\r |
9359e53f |
836 | @param DevicePath Console devcie's device path.\r |
c5ed97f6 |
837 | @param Operation Variable operations, including APPEND, CHECK and DELETE.\r |
9359e53f |
838 | \r |
839 | @retval EFI_SUCCESS Variable operates successfully.\r |
840 | @retval EFI_OUT_OF_RESOURCES If variable cannot be appended.\r |
841 | @retval other Variable updating failed.\r |
842 | \r |
843 | **/\r |
95276127 |
844 | EFI_STATUS\r |
845 | ConPlatformUpdateDeviceVariable (\r |
846 | IN CHAR16 *VariableName,\r |
847 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r |
848 | IN CONPLATFORM_VAR_OPERATION Operation\r |
849 | )\r |
95276127 |
850 | {\r |
851 | EFI_STATUS Status;\r |
852 | EFI_DEVICE_PATH_PROTOCOL *VariableDevicePath;\r |
853 | EFI_DEVICE_PATH_PROTOCOL *NewVariableDevicePath;\r |
854 | \r |
855 | VariableDevicePath = NULL;\r |
856 | NewVariableDevicePath = NULL;\r |
857 | \r |
858 | //\r |
859 | // Get Variable according to variable name.\r |
860 | // The memory for Variable is allocated within ConPlatformGetVarible(),\r |
861 | // it is the caller's responsibility to free the memory before return.\r |
862 | //\r |
863 | VariableDevicePath = ConPlatformGetVariable (VariableName);\r |
864 | \r |
865 | if (Operation != DELETE) {\r |
7b9ff698 |
866 | //\r |
867 | // Match specified DevicePath in Console Variable.\r |
868 | // \r |
95276127 |
869 | Status = ConPlatformMatchDevicePaths (\r |
c5ed97f6 |
870 | VariableDevicePath,\r |
871 | DevicePath,\r |
872 | NULL,\r |
873 | FALSE\r |
874 | );\r |
95276127 |
875 | \r |
876 | if ((Operation == CHECK) || (!EFI_ERROR (Status))) {\r |
877 | //\r |
c5ed97f6 |
878 | // Branch here includes 2 cases:\r |
879 | // 1. Operation is CHECK, simply return Status.\r |
880 | // 2. Operation is APPEND, and device path already exists in variable, also return.\r |
95276127 |
881 | //\r |
882 | if (VariableDevicePath != NULL) {\r |
883 | FreePool (VariableDevicePath);\r |
884 | }\r |
885 | \r |
886 | return Status;\r |
887 | }\r |
888 | //\r |
c5ed97f6 |
889 | // We reach here to append a device path that does not exist in variable.\r |
95276127 |
890 | //\r |
891 | Status = EFI_SUCCESS;\r |
892 | NewVariableDevicePath = AppendDevicePathInstance (\r |
893 | VariableDevicePath,\r |
894 | DevicePath\r |
895 | );\r |
896 | if (NewVariableDevicePath == NULL) {\r |
897 | Status = EFI_OUT_OF_RESOURCES;\r |
898 | }\r |
899 | \r |
900 | } else {\r |
901 | //\r |
c5ed97f6 |
902 | // We reach here to remove DevicePath from the environment variable that\r |
95276127 |
903 | // is a multi-instance device path.\r |
904 | //\r |
905 | Status = ConPlatformMatchDevicePaths (\r |
c5ed97f6 |
906 | VariableDevicePath,\r |
907 | DevicePath,\r |
908 | &NewVariableDevicePath,\r |
909 | TRUE\r |
910 | );\r |
95276127 |
911 | }\r |
912 | \r |
913 | if (VariableDevicePath != NULL) {\r |
914 | FreePool (VariableDevicePath);\r |
915 | }\r |
916 | \r |
917 | if (EFI_ERROR (Status)) {\r |
918 | return Status;\r |
919 | }\r |
920 | \r |
c62a593c |
921 | if (NewVariableDevicePath != NULL) {\r |
7b9ff698 |
922 | //\r |
923 | // Update Console Environment Variable.\r |
924 | //\r |
c62a593c |
925 | Status = gRT->SetVariable (\r |
926 | VariableName,\r |
927 | &gEfiGlobalVariableGuid,\r |
928 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r |
929 | GetDevicePathSize (NewVariableDevicePath),\r |
930 | NewVariableDevicePath\r |
931 | );\r |
95276127 |
932 | \r |
c62a593c |
933 | FreePool (NewVariableDevicePath);\r |
934 | }\r |
95276127 |
935 | \r |
936 | return Status;\r |
937 | }\r |
938 | \r |
9359e53f |
939 | /**\r |
ea1ac7a0 |
940 | Check if the device supports hot-plug through its device path.\r |
941 | \r |
942 | This function could be updated to check more types of Hot Plug devices.\r |
943 | Currently, it checks USB and PCCard device.\r |
9359e53f |
944 | \r |
ea1ac7a0 |
945 | @param DevicePath Pointer to device's device path.\r |
9359e53f |
946 | \r |
947 | @retval TRUE The devcie is a hot-plug device\r |
948 | @retval FALSE The devcie is not a hot-plug device.\r |
949 | \r |
950 | **/\r |
95276127 |
951 | BOOLEAN\r |
952 | IsHotPlugDevice (\r |
ea1ac7a0 |
953 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r |
95276127 |
954 | )\r |
955 | {\r |
95276127 |
956 | //\r |
ea1ac7a0 |
957 | // Check device whether is hot plug device or not throught Device Path\r |
958 | // \r |
959 | if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&\r |
960 | (DevicePathSubType (DevicePath) == MSG_USB_DP ||\r |
961 | DevicePathSubType (DevicePath) == MSG_USB_CLASS_DP ||\r |
962 | DevicePathSubType (DevicePath) == MSG_USB_WWID_DP)) {\r |
963 | //\r |
964 | // If Device is USB device\r |
965 | //\r |
966 | return TRUE;\r |
967 | }\r |
968 | if ((DevicePathType (DevicePath) == HARDWARE_DEVICE_PATH) &&\r |
969 | (DevicePathSubType (DevicePath) == HW_PCCARD_DP)) {\r |
970 | //\r |
971 | // If Device is PCCard\r |
972 | //\r |
973 | return TRUE;\r |
95276127 |
974 | }\r |
975 | \r |
ea1ac7a0 |
976 | return FALSE;\r |
95276127 |
977 | }\r |