metee: metee.h Source File

metee

Loading...
Searching...
No Matches
metee.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: Apache-2.0 */
2/*
3 * Copyright (C) 2014-2025 Intel Corporation
4 */
8#ifndef __METEE_H
9#define __METEE_H
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <stddef.h>
16#include <stdint.h>
17#include <stdbool.h>
19#ifdef _WIN32
20 #include <Windows.h>
21 #include <initguid.h>
22
23 #ifndef METEE_DLL
24 #define METEE_DLL_API
25 #else /* METEE_DLL */
26 #ifdef METEE_DLL_EXPORT
27 #define METEE_DLL_API __declspec(dllexport)
28 #else
29 #define METEE_DLL_API __declspec(dllimport)
30 #endif /* METEE_DLL_EXPORT */
31 #endif /* METEE_DLL */
32 #define TEEAPI METEE_DLL_API __stdcall
33 #define TEE_DEVICE_HANDLE HANDLE
34 #define TEE_INVALID_DEVICE_HANDLE ((void*)0)
35
36#elif defined(EFI)
37 #include <Uefi.h>
38 #define TEEAPI
39 #define TEE_DEVICE_HANDLE void *
40 #define TEE_INVALID_DEVICE_HANDLE ((void*)-1)
41
42 // when calling TeeInitFull
43 // TEE_DEVICE_TYPE_BDF - HECI device Bus Device Function
44
45#else /* _WIN32 */
46 #ifndef METEE_DLL
47 #define METEE_DLL_API
48 #else
49 #ifdef METEE_DLL_EXPORT
50 #define METEE_DLL_API __attribute__((__visibility__("default")))
51 #else
52 #define METEE_DLL_API
53 #endif /* METEE_DLL_EXPORT */
54 #endif /* METEE_DLL */
55 #define TEEAPI METEE_DLL_API
56
57 #ifndef GUID_DEFINED
58 #define GUID_DEFINED 1
59 typedef struct _GUID {
60 uint32_t l;
61 uint16_t w1;
62 uint16_t w2;
63 uint8_t b[8];
64 } GUID;
65 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
66 const GUID name \
67 = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
68 #endif /* GUID_DEFINED */
69
70 #define TEE_DEVICE_HANDLE int
71 #define TEE_INVALID_DEVICE_HANDLE (-1)
72 #ifndef IN
73 #define IN
74 #endif
75 #ifndef OUT
76 #define OUT
77 #endif
78 #ifndef OPTIONAL
79 #define OPTIONAL
80 #endif
81#endif /* _WIN32 */
83
86 enum tee_log_level {
87 TEE_LOG_LEVEL_QUIET = 0,
88 TEE_LOG_LEVEL_ERROR = 1,
89 TEE_LOG_LEVEL_VERBOSE = 2,
90 TEE_LOG_LEVEL_MAX = 3,
91};
92
95 typedef void(*TeeLogCallback)(bool is_error, const char* fmt, ...);
96
100 typedef struct _TEEHANDLE {
101
102 void *handle;
103 size_t maxMsgLen;
104 uint8_t protcolVer;
105 enum tee_log_level log_level;
106 TeeLogCallback log_callback;
107} TEEHANDLE;
108
113 typedef TEEHANDLE *PTEEHANDLE;
114
117 struct tee_device_address {
120 enum {
121 TEE_DEVICE_TYPE_NONE = 0,
122 TEE_DEVICE_TYPE_PATH = 1,
123 TEE_DEVICE_TYPE_HANDLE = 2,
124 TEE_DEVICE_TYPE_GUID = 3,
125 TEE_DEVICE_TYPE_BDF = 4,
126 TEE_DEVICE_TYPE_MAX = 5,
127 } type;
128
130 union {
131 const char* path;
132 const GUID* guid;
133 TEE_DEVICE_HANDLE handle;
134 struct {
135 struct {
136 uint32_t segment;
137 uint32_t bus;
138 uint32_t device;
139 uint32_t function;
140 } value;
142 enum HECI_HW_TYPE {
143 HECI_HW_TYPE_PCH,
144 HECI_HW_TYPE_GFX_GSC,
145 HECI_HW_TYPE_GFX_CSC,
146 } hw_type;
147 } bdf;
148 } data;
149};
150
152#define TEEHANDLE_ZERO {0}
153
154 typedef uint16_t TEESTATUS;
156#define TEE_ERROR_BASE 0x0000U
158#define TEE_SUCCESS (TEE_ERROR_BASE + 0)
160#define TEE_INTERNAL_ERROR (TEE_ERROR_BASE + 1)
162#define TEE_DEVICE_NOT_FOUND (TEE_ERROR_BASE + 2)
164#define TEE_DEVICE_NOT_READY (TEE_ERROR_BASE + 3)
166#define TEE_INVALID_PARAMETER (TEE_ERROR_BASE + 4)
168#define TEE_UNABLE_TO_COMPLETE_OPERATION (TEE_ERROR_BASE + 5)
170#define TEE_TIMEOUT (TEE_ERROR_BASE + 6)
172#define TEE_NOTSUPPORTED (TEE_ERROR_BASE + 7)
174#define TEE_CLIENT_NOT_FOUND (TEE_ERROR_BASE + 8)
176#define TEE_BUSY (TEE_ERROR_BASE + 9)
178#define TEE_DISCONNECTED (TEE_ERROR_BASE + 10)
180#define TEE_INSUFFICIENT_BUFFER (TEE_ERROR_BASE + 11)
182#define TEE_PERMISSION_DENIED (TEE_ERROR_BASE + 12)
183
186#define TEE_IS_SUCCESS(Status) (((TEESTATUS)(Status)) == TEE_SUCCESS)
187
197 TEESTATUS TEEAPI TeeInitFull(IN OUT PTEEHANDLE handle, IN const GUID* guid,
198 IN const struct tee_device_address device,
199 IN uint32_t log_level, IN OPTIONAL TeeLogCallback log_callback);
200
208 TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID *guid,
209 IN OPTIONAL const char *device);
210
211#ifdef _WIN32
220 TEESTATUS TEEAPI TeeInitGUID(IN OUT PTEEHANDLE handle, IN const GUID *guid,
221 IN OPTIONAL const GUID *device);
222#endif /* _WIN32 */
223
231 TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID *guid,
232 IN const TEE_DEVICE_HANDLE device_handle);
233
238 TEESTATUS TEEAPI TeeConnect(OUT PTEEHANDLE handle);
239
249 TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void *buffer, IN size_t bufferSize,
250 OUT OPTIONAL size_t *pNumOfBytesRead, IN OPTIONAL uint32_t timeout);
251
261 TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void *buffer, IN size_t bufferSize,
262 OUT OPTIONAL size_t *numberOfBytesWritten, IN OPTIONAL uint32_t timeout);
263
270 TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle,
271 IN uint32_t fwStatusNum, OUT uint32_t *fwStatus);
272
278 TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t* trc_val);
279
285 void TEEAPI TeeDisconnect(IN PTEEHANDLE handle);
286
292TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle);
293
296 typedef struct {
297 uint16_t major;
298 uint16_t minor;
299 uint16_t hotfix;
300 uint16_t build;
301} teeDriverVersion_t;
302
309 TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion);
310
317uint32_t TEEAPI TeeSetLogLevel(IN PTEEHANDLE handle, IN uint32_t log_level);
318
324uint32_t TEEAPI TeeGetLogLevel(IN const PTEEHANDLE handle);
325
332 TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback);
333
340uint32_t TEEAPI TeeGetMaxMsgLen(IN const PTEEHANDLE handle);
341
348uint8_t TEEAPI TeeGetProtocolVer(IN const PTEEHANDLE handle);
349
350
358 TEESTATUS TEEAPI TeeGetKind(IN PTEEHANDLE handle, IN OUT char *kind, IN OUT size_t *kindSize);
359
360#ifdef __cplusplus
361}
362#endif
363
364#endif /* __METEE_H */
TEESTATUS
uint16_t TEESTATUS
Definition metee.h:154
TeeLogCallback
void(* TeeLogCallback)(bool is_error, const char *fmt,...)
Definition metee.h:95
TeeSetLogCallback
TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback)
tee_log_level
tee_log_level
Definition metee.h:86
TEE_LOG_LEVEL_ERROR
@ TEE_LOG_LEVEL_ERROR
Definition metee.h:88
TEE_LOG_LEVEL_MAX
@ TEE_LOG_LEVEL_MAX
Definition metee.h:90
TEE_LOG_LEVEL_VERBOSE
@ TEE_LOG_LEVEL_VERBOSE
Definition metee.h:89
TEE_LOG_LEVEL_QUIET
@ TEE_LOG_LEVEL_QUIET
Definition metee.h:87
GetDriverVersion
TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion)
PTEEHANDLE
TEEHANDLE * PTEEHANDLE
A type definition for pointer to TEEHANDLE.
Definition metee.h:113
TeeRead
TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void *buffer, IN size_t bufferSize, OUT OPTIONAL size_t *pNumOfBytesRead, IN OPTIONAL uint32_t timeout)
TeeGetDeviceHandle
TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle)
TeeFWStatus
TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle, IN uint32_t fwStatusNum, OUT uint32_t *fwStatus)
TeeGetLogLevel
uint32_t TEEAPI TeeGetLogLevel(IN const PTEEHANDLE handle)
TeeGetTRC
TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t *trc_val)
TeeGetKind
TEESTATUS TEEAPI TeeGetKind(IN PTEEHANDLE handle, IN OUT char *kind, IN OUT size_t *kindSize)
TeeInitHandle
TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN const TEE_DEVICE_HANDLE device_handle)
TeeInit
TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN OPTIONAL const char *device)
TeeGetMaxMsgLen
uint32_t TEEAPI TeeGetMaxMsgLen(IN const PTEEHANDLE handle)
TeeDisconnect
void TEEAPI TeeDisconnect(IN PTEEHANDLE handle)
TeeConnect
TEESTATUS TEEAPI TeeConnect(OUT PTEEHANDLE handle)
TeeInitFull
TEESTATUS TEEAPI TeeInitFull(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN const struct tee_device_address device, IN uint32_t log_level, IN OPTIONAL TeeLogCallback log_callback)
TeeWrite
TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void *buffer, IN size_t bufferSize, OUT OPTIONAL size_t *numberOfBytesWritten, IN OPTIONAL uint32_t timeout)
TEEHANDLE
struct _TEEHANDLE TEEHANDLE
TeeSetLogLevel
uint32_t TEEAPI TeeSetLogLevel(IN PTEEHANDLE handle, IN uint32_t log_level)
TeeGetProtocolVer
uint8_t TEEAPI TeeGetProtocolVer(IN const PTEEHANDLE handle)
_TEEHANDLE
Definition metee.h:100
_TEEHANDLE::protcolVer
uint8_t protcolVer
Definition metee.h:104
_TEEHANDLE::log_callback
TeeLogCallback log_callback
Definition metee.h:106
_TEEHANDLE::log_level
enum tee_log_level log_level
Definition metee.h:105
_TEEHANDLE::maxMsgLen
size_t maxMsgLen
Definition metee.h:103
_TEEHANDLE::handle
void * handle
Definition metee.h:102
teeDriverVersion_t
Definition metee.h:296
teeDriverVersion_t::major
uint16_t major
Definition metee.h:297
teeDriverVersion_t::build
uint16_t build
Definition metee.h:300
teeDriverVersion_t::minor
uint16_t minor
Definition metee.h:298
teeDriverVersion_t::hotfix
uint16_t hotfix
Definition metee.h:299
tee_device_address
Definition metee.h:117
tee_device_address::TEE_DEVICE_TYPE_NONE
@ TEE_DEVICE_TYPE_NONE
Definition metee.h:121
tee_device_address::TEE_DEVICE_TYPE_GUID
@ TEE_DEVICE_TYPE_GUID
Definition metee.h:124
tee_device_address::TEE_DEVICE_TYPE_HANDLE
@ TEE_DEVICE_TYPE_HANDLE
Definition metee.h:123
tee_device_address::TEE_DEVICE_TYPE_PATH
@ TEE_DEVICE_TYPE_PATH
Definition metee.h:122
tee_device_address::TEE_DEVICE_TYPE_MAX
@ TEE_DEVICE_TYPE_MAX
Definition metee.h:126
tee_device_address::TEE_DEVICE_TYPE_BDF
@ TEE_DEVICE_TYPE_BDF
Definition metee.h:125
tee_device_address::device
uint32_t device
Definition metee.h:138
tee_device_address::function
uint32_t function
Definition metee.h:139
tee_device_address::handle
TEE_DEVICE_HANDLE handle
Definition metee.h:133
tee_device_address::data
union tee_device_address::@351101005315377115143207177217037041212124073312 data
tee_device_address::bus
uint32_t bus
Definition metee.h:137
tee_device_address::type
enum tee_device_address::@030156371030323311065310366271317131066163266361 type
tee_device_address::guid
const GUID * guid
Definition metee.h:132