1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef __BOOT_SERVICE_PROVIDER_
18 #define __BOOT_SERVICE_PROVIDER_
19 
20 #include <uefi/boot_service.h>
21 #include <uefi/system_table.h>
22 
23 void setup_boot_service_table(EfiBootService *service);
24 
25 static constexpr auto LOADED_IMAGE_PROTOCOL_GUID =
26     EfiGuid{0x5b1b31a1,
27             0x9562,
28             0x11d2,
29             {0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}};
30 
31 static constexpr auto EFI_DEVICE_PATH_PROTOCOL_GUID =
32     EfiGuid{0x9576e91,
33             0x6d3f,
34             0x11d2,
35             {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}};
36 
37 static constexpr auto LINUX_EFI_LOADED_IMAGE_FIXED_GUID =
38     EfiGuid{0xf5a37b6d,
39             0x3344,
40             0x42a5,
41             {0xb6, 0xbb, 0x97, 0x86, 0x48, 0xc1, 0x89, 0x0a}};
42 static constexpr auto EFI_RNG_PROTOCOL_GUID =
43     EfiGuid{0x3152bca5,
44             0xeade,
45             0x433d,
46             {0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44}};
47 
48 static constexpr auto EFI_TCG2_PROTOCOL_GUID =
49     EfiGuid{0x607f766c,
50             0x7455,
51             0x42be,
52             {0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f}};
53 
54 static constexpr auto EFI_LOAD_FILE2_PROTOCOL_GUID =
55     EfiGuid{0x4006c0c1,
56             0xfcb3,
57             0x403e,
58             {0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d}};
59 static constexpr auto EFI_BLOCK_IO_PROTOCOL_GUID =
60     EfiGuid{0x964e5b21,
61             0x6459,
62             0x11d2,
63             {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}};
64 
65 static constexpr auto EFI_BLOCK_IO2_PROTOCOL_GUID =
66     EfiGuid{0xa77b2472,
67             0xe282,
68             0x4e9f,
69             {0xa2, 0x45, 0xc2, 0xc0, 0xe2, 0x7b, 0xbc, 0xc1}};
70 
71 static constexpr auto EFI_TEXT_INPUT_PROTOCOL_GUID =
72     EfiGuid{0x387477c1,
73             0x69c7,
74             0x11d2,
75             {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}};
76 
77 static constexpr auto EFI_GBL_OS_CONFIGURATION_PROTOCOL_GUID =
78     EfiGuid{0xdda0d135,
79             0xaa5b,
80             0x42ff,
81             {0x85, 0xac, 0xe3, 0xad, 0x6e, 0xfb, 0x46, 0x19}};
82 
83 static constexpr auto EFI_GBL_EFI_IMAGE_LOADING_PROTOCOL_GUID =
84     EfiGuid{0xdb84b4fa,
85             0x53bd,
86             0x4436,
87             {0x98, 0xa7, 0x4e, 0x02, 0x71, 0x42, 0x8b, 0xa8}};
88 
89 static constexpr auto EFI_GBL_EFI_AB_SLOT_PROTOCOL_GUID =
90     EfiGuid{0x9a7a7db4,
91             0x614b,
92             0x4a08,
93             {0x3d, 0xf9, 0x00, 0x6f, 0x49, 0xb0, 0xd8, 0x0c}};
94 
95 static constexpr auto EFI_GBL_EFI_FASTBOOT_PROTOCOL_GUID =
96     EfiGuid{0xc67e48a0,
97             0x5eb8,
98             0x4127,
99             {0xbe, 0x89, 0xdf, 0x2e, 0xd9, 0x3d, 0x8a, 0x9a}};
100 
101 static constexpr auto EFI_GBL_EFI_FASTBOOT_TRANSPORT_PROTOCOL_GUID =
102     EfiGuid{0xedade92c,
103             0x5c48,
104             0x440d,
105             {0x84, 0x9c, 0xe2, 0xa0, 0xc7, 0xe5, 0x51, 0x43}};
106 
107 static constexpr auto EFI_DT_FIXUP_PROTOCOL_GUID =
108     EfiGuid{0xe617d64c,
109             0xfe08,
110             0x46da,
111             {0xf4, 0xdc, 0xbb, 0xd5, 0x87, 0x0c, 0x73, 0x00}};
112 
113 static constexpr auto EFI_TIMESTAMP_PROTOCOL_GUID =
114     EfiGuid{0xafbfde41,
115             0x2e6e,
116             0x4262,
117             {0xba, 0x65, 0x62, 0xb9, 0x23, 0x6e, 0x54, 0x95}};
118 
119 using EFI_IMAGE_UNLOAD = EfiStatus (*)(EfiHandle);
120 
121 //******************************************************
122 // EFI_DEVICE_PATH_PROTOCOL
123 //******************************************************
124 struct EFI_DEVICE_PATH_PROTOCOL {
125   uint8_t Type;
126   uint8_t SubType;
127   uint8_t Length[2];
128 };
129 
130 struct EFI_LOADED_IMAGE_PROTOCOL {
131   uint32_t Revision;
132   EfiHandle ParentHandle;
133   EfiSystemTable *SystemTable;
134 
135   // Source location of the image
136   EfiHandle DeviceHandle;
137   EFI_DEVICE_PATH_PROTOCOL *FilePath;
138   void *Reserved;
139 
140   // Image’s load options
141   uint32_t LoadOptionsSize;
142   void *LoadOptions;
143 
144   // Location where image was loaded
145   void *ImageBase;
146   uint64_t ImageSize;
147   EFI_MEMORY_TYPE ImageCodeType;
148   EFI_MEMORY_TYPE ImageDataType;
149   EFI_IMAGE_UNLOAD Unload;
150 };
151 
152 static constexpr size_t EFI_LOADED_IMAGE_PROTOCOL_REVISION = 0x1000;
153 
154 // This function would be called from GBL before jumping into android kernel
155 // LK provides a default no-op implementation that is weakly linked,
156 // different platforms can override with their own implementation.
157 EfiStatus exit_boot_services(EfiHandle image_handle, size_t map_key);
158 
159 #endif
160