Skip to content

Commit d2998af

Browse files
makubackimergify[bot]
authored andcommitted
PrmPkg: Add package and include headers
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3812 Adds a new package to maintain Platform Runtime Mechanism (PRM) support. This package is intended to include generic code that provides a common infrastructure to support PRM in firmware and a collection of sample PRM modules that demonstrate how to use the interfaces and other package resources to author a PRM module. The following initial headers are included in this commit: * Prm.h - Includes common content for PRM with no dependencies on other PRM header files. * PrmContextBuffer.h - Includes definitions for PRM context buffers. Context buffers are standardized structures that point to various resources available to a PRM handler during its execution. * PrmDataBuffer.h - Includes definitions for PRM data buffers. Within the context of PRM, these data buffers are composed of a generic header followed by a variable length blob of arbitrary data. * PrmExportDescriptor.h - Includes definitions for creating PRM export descriptors. A PRM export descriptor is a structure referenced in the export table of PRM module that contains PRM-specific metadata about the module. * PrmMmio.h - Includes definitions for describing MMIO ranges uses by PRM modules. * PrmModule.h - Includes definitions commonly used by PRM module authors. This file is provided to serve as a convenient include for PRM module authors. * PrmOsServices.h - Includes content specific to PRM OS services. OS Services will not planned to be present in the final version of PRM. The OS Services have been reduced to a simple debug print function. So this is currently planned to be a temporary file to support debugging during PRM development. Note: Modules built for the UEFI environment can be built by Visual Studio and non-Visual Studio toolchains. However, PRM modules are currently only supported on Visual Studio toolchain due to usage of export tables. Cc: Andrew Fish <[email protected]> Cc: Kang Gao <[email protected]> Cc: Michael D Kinney <[email protected]> Cc: Michael Kubacki <[email protected]> Cc: Leif Lindholm <[email protected]> Cc: Benjamin You <[email protected]> Cc: Liu Yun <[email protected]> Cc: Ankit Sinha <[email protected]> Cc: Nate DeSimone <[email protected]> Signed-off-by: Michael Kubacki <[email protected]> Acked-by: Michael D Kinney <[email protected]> Acked-by: Liming Gao <[email protected]> Acked-by: Leif Lindholm <[email protected]> Reviewed-by: Ankit Sinha <[email protected]>
1 parent ad6816c commit d2998af

10 files changed

+577
-0
lines changed

PrmPkg/Include/Prm.h

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/** @file
2+
3+
Common Platform Runtime Mechanism (PRM) definitions.
4+
5+
Copyright (c) Microsoft Corporation
6+
SPDX-License-Identifier: BSD-2-Clause-Patent
7+
8+
**/
9+
10+
#ifndef PRM_H_
11+
#define PRM_H_
12+
13+
#include <Uefi.h>
14+
#include <PrmContextBuffer.h>
15+
16+
#if defined(_MSC_VER)
17+
#define PRM_EXPORT_API __declspec(dllexport)
18+
#else
19+
#define PRM_EXPORT_API
20+
#endif
21+
22+
#define PRM_HANDLER_NAME_MAXIMUM_LENGTH 128
23+
24+
#define PRM_STRING_(x) #x
25+
#define PRM_STRING(x) PRM_STRING_(x)
26+
27+
/**
28+
A Platform Runtime Mechanism (PRM) handler function.
29+
30+
@param[in] ParameterBuffer A pointer to a buffer with arbitrary data that is allocated and populated
31+
by the PRM handler caller.
32+
@param[in] ContextBuffer A pointer to a buffer with arbitrary data that is allocated in the firmware
33+
boot environment.
34+
35+
@retval EFI_STATUS The PRM handler executed successfully.
36+
@retval Others An error occurred in the PRM handler.
37+
38+
**/
39+
typedef
40+
EFI_STATUS
41+
(EFIAPI PRM_HANDLER) (
42+
IN VOID *ParameterBuffer OPTIONAL,
43+
IN PRM_CONTEXT_BUFFER *ContextBuffer OPTIONAL
44+
);
45+
46+
#endif

PrmPkg/Include/PrmContextBuffer.h

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/** @file
2+
3+
Definitions for the Platform Runtime Mechanism (PRM) context buffer structures.
4+
5+
Copyright (c) Microsoft Corporation
6+
SPDX-License-Identifier: BSD-2-Clause-Patent
7+
8+
**/
9+
10+
#ifndef PRM_CONTEXT_BUFFER_H_
11+
#define PRM_CONTEXT_BUFFER_H_
12+
13+
#include <PrmDataBuffer.h>
14+
#include <PrmMmio.h>
15+
#include <Uefi.h>
16+
17+
#define PRM_CONTEXT_BUFFER_SIGNATURE SIGNATURE_32('P','R','M','C')
18+
#define PRM_CONTEXT_BUFFER_INTERFACE_VERSION 1
19+
20+
#pragma pack(push, 1)
21+
22+
//
23+
// This is the context buffer structure that is passed to a PRM handler.
24+
//
25+
// At OS runtime, the OS will allocate and populate this structure and
26+
// place virtual addresses in the pointer fields.
27+
//
28+
// It is also reused internally in FW (in the PRM_MODULE_CONTEXT_BUFFERS structure)
29+
// to track context buffers within a given PRM module. In that internal usage,
30+
// the addresses will be physical addresses.
31+
//
32+
typedef struct {
33+
///
34+
/// Signature of this interface.
35+
///
36+
UINT32 Signature;
37+
38+
///
39+
/// Version of this interface.
40+
///
41+
UINT16 Version;
42+
43+
///
44+
/// Reserved field.
45+
///
46+
UINT16 Reserved;
47+
48+
///
49+
/// The GUID of the PRM handler represented by this context instance.
50+
///
51+
EFI_GUID HandlerGuid;
52+
53+
///
54+
/// A virtual address pointer to the static data buffer allocated for
55+
/// the PRM handler represented by this context instance.
56+
///
57+
/// The static buffer is intended to be populated in the PRM module
58+
/// configuration library and treated as read-only data at OS runtime.
59+
///
60+
/// This pointer may be NULL if a static data buffer is not needed.
61+
///
62+
PRM_DATA_BUFFER *StaticDataBuffer;
63+
64+
///
65+
/// A virtual address pointer to an array of PRM_RUNTIME_MMIO_RANGE
66+
/// structures that describe MMIO physical address ranges mapped to
67+
/// virtual memory addresses for access at OS runtime.
68+
///
69+
/// This pointer is ignored in firmware internal usage of this structure
70+
/// as this field is present to allow a PRM handler to get the list
71+
/// of MMIO ranges described as accessible by its PRM module.
72+
///
73+
/// The module list of MMIO ranges is specified by the PRM configuration
74+
/// code as a single array in PRM_MODULE_CONTEXT_BUFFERS.
75+
///
76+
/// The OS is responsible for ensuring the pointer to the array in this
77+
/// structure is converted to a virtual address during construction of
78+
/// of the context buffer in the OS.
79+
///
80+
/// This pointer may be NULL if runtime memory ranges are not needed.
81+
///
82+
PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges;
83+
} PRM_CONTEXT_BUFFER;
84+
85+
//
86+
// A firmware internal data structure used to track context buffer and
87+
// runtime MMIO range usage across a PRM module.
88+
//
89+
typedef struct
90+
{
91+
///
92+
/// The GUID of the PRM module.
93+
///
94+
EFI_GUID ModuleGuid;
95+
96+
///
97+
/// The number of PRM context buffers in ContextBuffers[].
98+
/// This count should equal the number of PRM handlers in the module being configured.
99+
///
100+
UINTN BufferCount;
101+
102+
///
103+
/// A pointer to an array of PRM context buffers
104+
///
105+
PRM_CONTEXT_BUFFER *Buffer;
106+
107+
/// The MMIO ranges are defined in the firmware boot environment.
108+
/// The addresses within the PRM_RUNTIME_MMIO_RANGES structure will
109+
/// be converted to virtual addresses by firmware.
110+
111+
///
112+
/// A physical address pointer to an array of PRM_RUNTIME_MMIO_RANGE
113+
/// structures that describe memory ranges that need to be mapped to
114+
/// virtual memory addresses for access at OS runtime.
115+
///
116+
/// This is a consolidated array of MMIO ranges accessed by any PRM
117+
/// handler in the PRM module at OS runtime. The MMIO range physical
118+
/// addresses registered here will automatically be converted to the
119+
/// corresponding virtual address in the structure by PRM infrastructure
120+
/// code. No action is required to convert MMIO range base physical
121+
/// addresses to virtual addresses by either the PRM configuration code
122+
/// or the OS.
123+
///
124+
/// This pointer may be NULL if runtime memory ranges are not needed.
125+
///
126+
PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges;
127+
} PRM_MODULE_CONTEXT_BUFFERS;
128+
129+
#pragma pack(pop)
130+
131+
#endif

PrmPkg/Include/PrmDataBuffer.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/** @file
2+
3+
Definitions for the Platform Runtime Mechanism (PRM) data buffer structures.
4+
5+
Copyright (c) Microsoft Corporation
6+
SPDX-License-Identifier: BSD-2-Clause-Patent
7+
8+
**/
9+
10+
#ifndef PRM_DATA_BUFFER_H_
11+
#define PRM_DATA_BUFFER_H_
12+
13+
#include <Uefi.h>
14+
15+
#define PRM_DATA_BUFFER_HEADER_SIGNATURE SIGNATURE_32('P','R','M','D')
16+
17+
#pragma pack(push, 1)
18+
19+
///
20+
/// A generic header that describes the PRM data buffer.
21+
///
22+
typedef struct {
23+
///
24+
/// PRM Data Buffer signature.
25+
///
26+
UINT32 Signature;
27+
///
28+
/// Length of the entire data buffer, including the size of the header.
29+
///
30+
UINT32 Length;
31+
} PRM_DATA_BUFFER_HEADER;
32+
33+
///
34+
/// A PRM data buffer is a generic header followed by variable length arbitrary data.
35+
///
36+
typedef struct {
37+
///
38+
/// The header is required at the beginning of every PRM data buffer.
39+
///
40+
PRM_DATA_BUFFER_HEADER Header;
41+
42+
///
43+
/// The beginning of data immediately follows the header.
44+
///
45+
UINT8 Data[1];
46+
} PRM_DATA_BUFFER;
47+
48+
#pragma pack(pop)
49+
50+
#endif

PrmPkg/Include/PrmExportDescriptor.h

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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_HANDLER_EXPORT_DESCRIPTOR_STRUCT PrmHandlerExportDescriptors[3];
35+
} PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT;
36+
37+
#pragma pack(pop)
38+
39+
/**
40+
A macro that declares a PRM Handler Export Descriptor for a PRM Handler.
41+
42+
This macro is intended to be used once per PRM Handler to describe the handler when the
43+
module description is defined. It should be provided as an argument to PRM_MODULE_EXPORT.
44+
45+
@param Guid The GUID of the PRM Handler being exported.
46+
47+
@param Name The name of the PRM Handler being exported. This string should exactly
48+
match the function name.
49+
50+
**/
51+
#define PRM_HANDLER_EXPORT_ENTRY(Guid, Name) \
52+
{ \
53+
Guid, \
54+
PRM_STRING_(Name) \
55+
} \
56+
57+
/**
58+
A macro that returns the count of the number of variable-length arguments given.
59+
60+
@param VariableArgumentList A variable argument list of elements that will be included
61+
in the return value of the list count.
62+
**/
63+
#define VA_ARG_COUNT(...) (sizeof((PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT[]){__VA_ARGS__})/sizeof(PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT))
64+
65+
/**
66+
A macro that declares the PRM Module Export Descriptor for a PRM Module.
67+
68+
This macro is intended to be used once in a PRM Module after all of the PRM Handler definitions
69+
to describe the PRM Handlers being exported in the module.
70+
71+
@param PrmHandlerExportEntries A variable argument list of PRM_HANDLER_EXPORT_ENTRY values.
72+
This list should include all PRM Handlers being exported by
73+
this module.
74+
75+
**/
76+
#define PRM_MODULE_EXPORT(...) \
77+
PRM_EXPORT_API PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT PRM_MODULE_EXPORT_DESCRIPTOR_NAME = { \
78+
{ \
79+
PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE, \
80+
PRM_MODULE_EXPORT_REVISION, \
81+
VA_ARG_COUNT(__VA_ARGS__), \
82+
EFI_CALLER_ID_GUID \
83+
}, \
84+
{ __VA_ARGS__ } \
85+
} \
86+
87+
#endif

PrmPkg/Include/PrmMmio.h

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/** @file
2+
3+
Definitions for the Platform Runtime Mechanism (PRM) MMIO elements.
4+
5+
Copyright (c) Microsoft Corporation
6+
SPDX-License-Identifier: BSD-2-Clause-Patent
7+
8+
**/
9+
10+
#ifndef PRM_MMIO_H_
11+
#define PRM_MMIO_H_
12+
13+
#include <Uefi.h>
14+
15+
#pragma pack(push, 1)
16+
17+
///
18+
/// Describes a memory range that needs to be made accessible at OS runtime.
19+
///
20+
/// The memory range with the given base address and length will be marked as EFI_MEMORY_RUNTIME.
21+
///
22+
typedef struct {
23+
EFI_PHYSICAL_ADDRESS PhysicalBaseAddress;
24+
EFI_PHYSICAL_ADDRESS VirtualBaseAddress;
25+
UINT32 Length;
26+
} PRM_RUNTIME_MMIO_RANGE;
27+
28+
///
29+
/// Describes a buffer with an array of PRM module
30+
/// config runtime memory ranges.
31+
///
32+
typedef struct {
33+
///
34+
/// The number of runtime memory range elements in this buffer.
35+
///
36+
UINT64 Count;
37+
///
38+
/// The beginning of the runtime memory range data.
39+
///
40+
PRM_RUNTIME_MMIO_RANGE Range[1];
41+
} PRM_RUNTIME_MMIO_RANGES;
42+
43+
#pragma pack(pop)
44+
45+
#endif

0 commit comments

Comments
 (0)