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 #ifndef __DEBUG_SUPPORT_
19 #define __DEBUG_SUPPORT_
20 
21 #include <lib/bio.h>
22 #include <uefi/system_table.h>
23 #include <uefi/types.h>
24 
25 static constexpr auto EFI_DEBUG_IMAGE_INFO_TABLE_GUID =
26     EfiGuid{0x49152e77,
27             0x1ada,
28             0x4764,
29             {0xb7, 0xa2, 0x7a, 0xfe, 0xfe, 0xd9, 0x5e, 0x8b}};
30 
31 static constexpr size_t EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS = 0x01;
32 static constexpr size_t EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED = 0x02;
33 
34 static constexpr size_t EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL = 0x01;
35 
36 struct EfiSystemTablePointer {
37   uint64_t signature;
38   EfiSystemTable *system_table_base;
39   uint32_t crc32;
40 };
41 
42 struct EfiDebugImageInfoNormal {
43   uint32_t image_info_type;
44   struct EFI_LOADED_IMAGE_PROTOCOL *loaded_image_protocol_instance;
45   EfiHandle image_handle;
46 };
47 
48 union EfiDebugImageInfo {
49   uint32_t *image_info_type;
50   struct EfiDebugImageInfoNormal *normal_image;
51 };
52 
53 struct EfiDebugImageInfoTableHeader {
54   volatile uint32_t update_status;
55   uint32_t table_size;
56   union EfiDebugImageInfo *efi_debug_image_info_table;
57 };
58 
59 EfiStatus efi_initialize_system_table_pointer(struct EfiSystemTable *system_table);
60 EfiStatus efi_core_new_debug_image_info_entry(uint32_t image_info_type,
61                                               struct EFI_LOADED_IMAGE_PROTOCOL *loaded_image,
62                                               EfiHandle image_handle);
63 void efi_core_remove_debug_image_info_entry(EfiHandle image_handle);
64 EfiStatus setup_debug_support(EfiSystemTable &table,
65 			      char *image_base,
66 			      size_t virtual_size,
67 			      bdev_t *dev);
68 
69 void teardown_debug_support(char *image_base);
70 
71 extern struct EfiDebugImageInfoTableHeader efi_m_debug_info_table_header;
72 
73 #endif
74