--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation \r
+All rights reserved. This program and the accompanying materials \r
+are licensed and made available under the terms and conditions of the BSD License \r
+which accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
+ \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+\r
+Module Name:\r
+\r
+ UnixUgaDriver.c\r
+\r
+Abstract:\r
+\r
+ This file implements the EFI 1.1 Device Driver model requirements for UGA\r
+\r
+ UGA is short hand for Universal Graphics Abstraction protocol.\r
+\r
+ This file is a verision of UgaIo the uses UnixThunk system calls as an IO \r
+ abstraction. For a PCI device UnixIo would be replaced with\r
+ a PCI IO abstraction that abstracted a specific PCI device. \r
+\r
+--*/\r
+\r
+#include "UnixUga.h"\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gUnixUgaDriverBinding = {\r
+ UnixUgaDriverBindingSupported,\r
+ UnixUgaDriverBindingStart,\r
+ UnixUgaDriverBindingStop,\r
+ 0xa,\r
+ NULL,\r
+ NULL\r
+};\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixUgaDriverBindingSupported (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Handle,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+// TODO: This - add argument and description to function comment\r
+// TODO: Handle - add argument and description to function comment\r
+// TODO: RemainingDevicePath - add argument and description to function comment\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_UNIX_IO_PROTOCOL *UnixIo;\r
+\r
+ //\r
+ // Open the IO Abstraction(s) needed to perform the supported test\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ Handle,\r
+ &gEfiUnixIoProtocolGuid,\r
+ (VOID **)&UnixIo,\r
+ This->DriverBindingHandle,\r
+ Handle,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Status = UnixUgaSupported (UnixIo);\r
+\r
+ //\r
+ // Close the I/O Abstraction(s) used to perform the supported test\r
+ //\r
+ gBS->CloseProtocol (\r
+ Handle,\r
+ &gEfiUnixIoProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Handle\r
+ );\r
+\r
+ return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixUgaDriverBindingStart (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Handle,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+// TODO: This - add argument and description to function comment\r
+// TODO: Handle - add argument and description to function comment\r
+// TODO: RemainingDevicePath - add argument and description to function comment\r
+// TODO: EFI_UNSUPPORTED - add return value to function comment\r
+{\r
+ EFI_UNIX_IO_PROTOCOL *UnixIo;\r
+ EFI_STATUS Status;\r
+ UGA_PRIVATE_DATA *Private;\r
+\r
+ //\r
+ // Grab the protocols we need\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ Handle,\r
+ &gEfiUnixIoProtocolGuid,\r
+ (VOID **)&UnixIo,\r
+ This->DriverBindingHandle,\r
+ Handle,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ //\r
+ // Allocate Private context data for SGO inteface.\r
+ //\r
+ Private = NULL;\r
+ Status = gBS->AllocatePool (\r
+ EfiBootServicesData,\r
+ sizeof (UGA_PRIVATE_DATA),\r
+ (VOID **)&Private\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+ //\r
+ // Set up context record\r
+ //\r
+ Private->Signature = UGA_PRIVATE_DATA_SIGNATURE;\r
+ Private->Handle = Handle;\r
+ Private->UnixThunk = UnixIo->UnixThunk;\r
+\r
+ Private->ControllerNameTable = NULL;\r
+\r
+ AddUnicodeString (\r
+ "eng",\r
+ gUnixUgaComponentName.SupportedLanguages,\r
+ &Private->ControllerNameTable,\r
+ UnixIo->EnvString\r
+ );\r
+\r
+ Private->WindowName = UnixIo->EnvString;\r
+\r
+ Status = UnixUgaConstructor (Private);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+ //\r
+ // Publish the Uga interface to the world\r
+ //\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &Private->Handle,\r
+ &gEfiUgaDrawProtocolGuid,\r
+ &Private->UgaDraw,\r
+ &gEfiSimpleTextInProtocolGuid,\r
+ &Private->SimpleTextIn,\r
+ NULL\r
+ );\r
+\r
+Done:\r
+ if (EFI_ERROR (Status)) {\r
+\r
+ gBS->CloseProtocol (\r
+ Handle,\r
+ &gEfiUnixIoProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Handle\r
+ );\r
+\r
+ if (Private != NULL) {\r
+ //\r
+ // On Error Free back private data\r
+ //\r
+ if (Private->ControllerNameTable != NULL) {\r
+ FreeUnicodeStringTable (Private->ControllerNameTable);\r
+ }\r
+\r
+ gBS->FreePool (Private);\r
+ }\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixUgaDriverBindingStop (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Handle,\r
+ IN UINTN NumberOfChildren,\r
+ IN EFI_HANDLE *ChildHandleBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+// TODO: This - add argument and description to function comment\r
+// TODO: Handle - add argument and description to function comment\r
+// TODO: NumberOfChildren - add argument and description to function comment\r
+// TODO: ChildHandleBuffer - add argument and description to function comment\r
+// TODO: EFI_NOT_STARTED - add return value to function comment\r
+// TODO: EFI_DEVICE_ERROR - add return value to function comment\r
+{\r
+ EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
+ EFI_STATUS Status;\r
+ UGA_PRIVATE_DATA *Private;\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Handle,\r
+ &gEfiUgaDrawProtocolGuid,\r
+ (VOID **)&UgaDraw,\r
+ This->DriverBindingHandle,\r
+ Handle,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ //\r
+ // If the UGA interface does not exist the driver is not started\r
+ //\r
+ return EFI_NOT_STARTED;\r
+ }\r
+\r
+ //\r
+ // Get our private context information\r
+ //\r
+ Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (UgaDraw);\r
+\r
+ //\r
+ // Remove the SGO interface from the system\r
+ //\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ Private->Handle,\r
+ &gEfiUgaDrawProtocolGuid,\r
+ &Private->UgaDraw,\r
+ &gEfiSimpleTextInProtocolGuid,\r
+ &Private->SimpleTextIn,\r
+ NULL\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ //\r
+ // Shutdown the hardware\r
+ //\r
+ Status = UnixUgaDestructor (Private);\r
+ if (EFI_ERROR (Status)) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ gBS->CloseProtocol (\r
+ Handle,\r
+ &gEfiUnixIoProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Handle\r
+ );\r
+\r
+ //\r
+ // Free our instance data\r
+ //\r
+ FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+ gBS->FreePool (Private);\r
+\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r