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