]> git.proxmox.com Git - mirror_edk2.git/blob - PrmPkg/Include/PrmExportDescriptor.h
PrmPkg: Enable variable growth for the PRM_MODULE_EXPORT macro
[mirror_edk2.git] / PrmPkg / Include / PrmExportDescriptor.h
1 /** @file
2
3 Definitions for the Platform Runtime Mechanism (PRM) export descriptor structures.
4
5 Copyright (c) Microsoft Corporation
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef PRM_EXPORT_DESCRIPTOR_H_
11 #define PRM_EXPORT_DESCRIPTOR_H_
12
13 #include <Prm.h>
14
15 #define PRM_MODULE_EXPORT_DESCRIPTOR_NAME PrmModuleExportDescriptor
16 #define PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE SIGNATURE_64 ('P', 'R', 'M', '_', 'M', 'E', 'D', 'T')
17 #define PRM_MODULE_EXPORT_REVISION 0x0
18
19 //
20 // Platform Runtime Mechanism (PRM) Export Descriptor Structures
21 //
22 #pragma pack(push, 1)
23
24 typedef struct {
25 GUID PrmHandlerGuid;
26 CHAR8 PrmHandlerName[PRM_HANDLER_NAME_MAXIMUM_LENGTH];
27 } PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT;
28
29 typedef struct {
30 UINT64 Signature;
31 UINT16 Revision;
32 UINT16 NumberPrmHandlers;
33 GUID ModuleGuid;
34 } PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER;
35
36 typedef struct {
37 PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER Header;
38 PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT PrmHandlerExportDescriptors[1];
39 } PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT;
40
41 #pragma pack(pop)
42
43 #if defined(_MSC_VER)
44 #define PRM_PACKED_STRUCT(definition) \
45 __pragma(pack(push, 1)) typedef struct definition __pragma(pack(pop))
46 #elif defined (__GNUC__) || defined (__clang__)
47 #define PRM_PACKED_STRUCT(definition) \
48 typedef struct __attribute__((packed)) definition
49 #endif
50
51 /**
52 A macro that declares a PRM Handler Export Descriptor for a PRM Handler.
53
54 This macro is intended to be used once per PRM Handler to describe the handler when the
55 module description is defined. It should be provided as an argument to PRM_MODULE_EXPORT.
56
57 @param Guid The GUID of the PRM Handler being exported.
58
59 @param Name The name of the PRM Handler being exported. This string should exactly
60 match the function name.
61
62 **/
63 #define PRM_HANDLER_EXPORT_ENTRY(Guid, Name) \
64 { \
65 Guid, \
66 PRM_STRING_(Name) \
67 } \
68
69 /**
70 A macro that returns the count of the number of variable-length arguments given.
71
72 @param VariableArgumentList A variable argument list of elements that will be included
73 in the return value of the list count.
74 **/
75 #define VA_ARG_COUNT(...) (sizeof((PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT[]){__VA_ARGS__})/sizeof(PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT))
76
77 /**
78 A macro that declares the PRM Module Export Descriptor for a PRM Module.
79
80 This macro is intended to be used once in a PRM Module after all of the PRM Handler definitions
81 to describe the PRM Handlers being exported in the module.
82
83 @param PrmHandlerExportEntries A variable argument list of PRM_HANDLER_EXPORT_ENTRY values.
84 This list should include all PRM Handlers being exported by
85 this module.
86
87 **/
88 #define PRM_MODULE_EXPORT(...) \
89 PRM_PACKED_STRUCT( \
90 { \
91 PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER Header; \
92 PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT PrmHandlerExportDescriptors[VA_ARG_COUNT(__VA_ARGS__)]; \
93 } PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_ \
94 ); \
95 \
96 PRM_EXPORT_API PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_ PRM_MODULE_EXPORT_DESCRIPTOR_NAME = { \
97 { \
98 PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE, \
99 PRM_MODULE_EXPORT_REVISION, \
100 VA_ARG_COUNT(__VA_ARGS__), \
101 EFI_CALLER_ID_GUID \
102 }, \
103 { __VA_ARGS__ } \
104 } \
105
106 #endif