1 /*
2  * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef COMMON_EFI_TYPES_H
8 #define COMMON_EFI_TYPES_H
9 
10 #include <stdbool.h>
11 #include <stdint.h>
12 #include <string.h>
13 
14 /**
15  * Common EFI types
16  */
17 
18 /**
19  * 128 bit buffer containing a unique identifier value.
20  * Unless otherwise specified, aligned on a 64 bit boundary.
21  */
22 typedef struct {
23 	uint32_t Data1;
24 	uint16_t Data2;
25 	uint16_t Data3;
26 	uint8_t  Data4[8];
27 } EFI_GUID;
28 
29 /**
30  * Common time representation
31  */
32 typedef struct {
33 	uint16_t  Year;
34 	uint8_t   Month;
35 	uint8_t   Day;
36 	uint8_t   Hour;
37 	uint8_t   Minute;
38 	uint8_t   Second;
39 	uint8_t   Pad1;
40 	uint32_t  Nanosecond;
41 	uint16_t  TimeZone;
42 	uint8_t   Daylight;
43 	uint8_t   Pad2;
44 } EFI_TIME;
45 
46 /**
47  * Header structure of messages in the MM communication buffer.
48  */
49 typedef struct {
50 	EFI_GUID HeaderGuid;
51 	uint64_t MessageLength;
52 	uint8_t Data[1];
53 } EFI_MM_COMMUNICATE_HEADER;
54 
55 /**
56  * Size of the EFI MM_COMMUNICATE header without the data field.
57  */
58 #define EFI_MM_COMMUNICATE_HEADER_SIZE	\
59 	(offsetof(EFI_MM_COMMUNICATE_HEADER, Data))
60 
61 /*
62  * Returns whether the two guid-s equal. To avoid structure padding related error
63  * the fields are checked separately instead of memcmp.
64  */
compare_guid(const EFI_GUID * guid1,const EFI_GUID * guid2)65 static inline bool compare_guid(const EFI_GUID *guid1, const EFI_GUID *guid2)
66 {
67 	return guid1->Data1 == guid2->Data1 && guid1->Data2 == guid2->Data2 &&
68 	       guid1->Data3 == guid2->Data3 &&
69 	       !memcmp(&guid1->Data4, &guid2->Data4, sizeof(guid1->Data4));
70 }
71 
72 #endif /* COMMON_EFI_TYPES_H */
73