Home | History | Annotate | Download | only in Logo
      1 /** @file
      2   Logo DXE Driver, install Edkii Platform Logo protocol.
      3 
      4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
      5 This program and the accompanying materials
      6 are licensed and made available under the terms and conditions of the BSD License
      7 which accompanies this distribution.  The full text of the license may be found at
      8 http://opensource.org/licenses/bsd-license.php
      9 
     10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 #include <Uefi.h>
     15 #include <Protocol/HiiDatabase.h>
     16 #include <Protocol/GraphicsOutput.h>
     17 #include <Protocol/HiiImageEx.h>
     18 #include <Protocol/PlatformLogo.h>
     19 #include <Protocol/HiiPackageList.h>
     20 #include <Library/UefiBootServicesTableLib.h>
     21 #include <Library/DebugLib.h>
     22 
     23 typedef struct {
     24   EFI_IMAGE_ID                          ImageId;
     25   EDKII_PLATFORM_LOGO_DISPLAY_ATTRIBUTE Attribute;
     26   INTN                                  OffsetX;
     27   INTN                                  OffsetY;
     28 } LOGO_ENTRY;
     29 
     30 EFI_HII_IMAGE_EX_PROTOCOL *mHiiImageEx;
     31 EFI_HII_HANDLE            mHiiHandle;
     32 LOGO_ENTRY                mLogos[] = {
     33   {
     34     IMAGE_TOKEN (IMG_LOGO),
     35     EdkiiPlatformLogoDisplayAttributeCenter,
     36     0,
     37     0
     38   }
     39 };
     40 
     41 /**
     42   Load a platform logo image and return its data and attributes.
     43 
     44   @param This              The pointer to this protocol instance.
     45   @param Instance          The visible image instance is found.
     46   @param Image             Points to the image.
     47   @param Attribute         The display attributes of the image returned.
     48   @param OffsetX           The X offset of the image regarding the Attribute.
     49   @param OffsetY           The Y offset of the image regarding the Attribute.
     50 
     51   @retval EFI_SUCCESS      The image was fetched successfully.
     52   @retval EFI_NOT_FOUND    The specified image could not be found.
     53 **/
     54 EFI_STATUS
     55 EFIAPI
     56 GetImage (
     57   IN     EDKII_PLATFORM_LOGO_PROTOCOL          *This,
     58   IN OUT UINT32                                *Instance,
     59      OUT EFI_IMAGE_INPUT                       *Image,
     60      OUT EDKII_PLATFORM_LOGO_DISPLAY_ATTRIBUTE *Attribute,
     61      OUT INTN                                  *OffsetX,
     62      OUT INTN                                  *OffsetY
     63   )
     64 {
     65   UINT32 Current;
     66   if (Instance == NULL || Image == NULL ||
     67       Attribute == NULL || OffsetX == NULL || OffsetY == NULL) {
     68     return EFI_INVALID_PARAMETER;
     69   }
     70 
     71   Current = *Instance;
     72   if (Current >= ARRAY_SIZE (mLogos)) {
     73     return EFI_NOT_FOUND;
     74   }
     75 
     76   (*Instance)++;
     77   *Attribute = mLogos[Current].Attribute;
     78   *OffsetX   = mLogos[Current].OffsetX;
     79   *OffsetY   = mLogos[Current].OffsetY;
     80   return mHiiImageEx->GetImageEx (mHiiImageEx, mHiiHandle, mLogos[Current].ImageId, Image);
     81 }
     82 
     83 EDKII_PLATFORM_LOGO_PROTOCOL mPlatformLogo = {
     84   GetImage
     85 };
     86 
     87 /**
     88   Entrypoint of this module.
     89 
     90   This function is the entrypoint of this module. It installs the Edkii
     91   Platform Logo protocol.
     92 
     93   @param  ImageHandle       The firmware allocated handle for the EFI image.
     94   @param  SystemTable       A pointer to the EFI System Table.
     95 
     96   @retval EFI_SUCCESS       The entry point is executed successfully.
     97 
     98 **/
     99 EFI_STATUS
    100 EFIAPI
    101 InitializeLogo (
    102   IN EFI_HANDLE               ImageHandle,
    103   IN EFI_SYSTEM_TABLE         *SystemTable
    104   )
    105 {
    106   EFI_STATUS                  Status;
    107   EFI_HII_PACKAGE_LIST_HEADER *PackageList;
    108   EFI_HII_DATABASE_PROTOCOL   *HiiDatabase;
    109   EFI_HANDLE                  Handle;
    110 
    111   Status = gBS->LocateProtocol (
    112                   &gEfiHiiDatabaseProtocolGuid,
    113                   NULL,
    114                   (VOID **) &HiiDatabase
    115                   );
    116   ASSERT_EFI_ERROR (Status);
    117 
    118   Status = gBS->LocateProtocol (
    119                   &gEfiHiiImageExProtocolGuid,
    120                   NULL,
    121                   (VOID **) &mHiiImageEx
    122                   );
    123   ASSERT_EFI_ERROR (Status);
    124 
    125   //
    126   // Retrieve HII package list from ImageHandle
    127   //
    128   Status = gBS->OpenProtocol (
    129                   ImageHandle,
    130                   &gEfiHiiPackageListProtocolGuid,
    131                   (VOID **) &PackageList,
    132                   ImageHandle,
    133                   NULL,
    134                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
    135                   );
    136   ASSERT_EFI_ERROR (Status);
    137 
    138   //
    139   // Publish HII package list to HII Database.
    140   //
    141   Status = HiiDatabase->NewPackageList (
    142                           HiiDatabase,
    143                           PackageList,
    144                           NULL,
    145                           &mHiiHandle
    146                           );
    147   if (!EFI_ERROR (Status)) {
    148     Handle = NULL;
    149     Status = gBS->InstallMultipleProtocolInterfaces (
    150                     &Handle,
    151                     &gEdkiiPlatformLogoProtocolGuid, &mPlatformLogo,
    152                     NULL
    153                     );
    154   }
    155   return Status;
    156 }
    157