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 
18 // This is a custom protocol introduced by GBL.
19 // See gbl/docs/gbl_efi_os_configuration_protocol.md for details.
20 
21 #ifndef __GBL_OS_CONFIGURATION_PROTOCOL_H__
22 #define __GBL_OS_CONFIGURATION_PROTOCOL_H__
23 
24 #include <uefi/types.h>
25 
26 static constexpr size_t GBL_EFI_OS_CONFIGURATION_PROTOCOL_REVISION = 0x00000000;
27 typedef enum GBL_EFI_DEVICE_TREE_TYPE {
28   // HLOS device tree.
29   DEVICE_TREE,
30   // HLOS device tree overlay.
31   OVERLAY,
32   // pVM device assignment overlay.
33   PVM_DA_OVERLAY,
34 } GblEfiDeviceTreeType;
35 
36 typedef enum GBL_EFI_DEVICE_TREE_SOURCE {
37   // Device tree loaded from boot partition.
38   BOOT,
39   // Device tree loaded from vendor_boot partition.
40   VENDOR_BOOT,
41   // Device tree loaded from dtbo partition.
42   DTBO,
43   // Device tree loaded from dtb partition.
44   DTB,
45 } GblEfiDeviceTreeSource;
46 
47 typedef struct {
48   // GblDeviceTreeSource
49   uint32_t source;
50   // GblDeviceTreeType
51   uint32_t type;
52   // Values are zeroed and must not be used in case of BOOT / VENDOR_BOOT source
53   uint32_t id;
54   uint32_t rev;
55   uint32_t custom[4];
56 } GblEfiDeviceTreeMetadata;
57 
58 typedef struct {
59   GblEfiDeviceTreeMetadata metadata;
60   // Base device tree / overlay buffer (guaranteed to be 8-bytes aligned),
61   // cannot be NULL. Device tree size can be identified by the header totalsize
62   // field
63   const void *device_tree;
64   // Indicates whether this device tree (or overlay) must be included in the
65   // final device tree. Set to true by a FW if this component must be used
66   bool selected;
67 } GblEfiVerifiedDeviceTree;
68 
69 // Warning: API is UNSTABLE
70 // Documentation:
71 // https://cs.android.com/android/kernel/superproject/+/common-android-mainline:bootable/libbootloader/gbl/docs/gbl_os_configuration_protocol.md
72 typedef struct GblEfiOsConfigurationProtocol {
73   uint64_t revision;
74 
75   // Generates fixups for the bootconfig built by GBL.
76   EfiStatus (*fixup_bootconfig)(struct GblEfiOsConfigurationProtocol *self,
77                                 const char *bootconfig, size_t size,
78                                 char *fixup, size_t *fixup_buffer_size);
79 
80   // Selects which device trees and overlays to use from those loaded by GBL.
81   EfiStatus (*select_device_trees)(struct GblEfiOsConfigurationProtocol *self,
82                                    GblEfiVerifiedDeviceTree *device_trees,
83                                    size_t num_device_trees);
84 } GblEfiOsConfigurationProtocol;
85 
86 #endif //__GBL_OS_CONFIGURATION_PROTOCOL_H__