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-2026 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 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
43 const GUID name \
44 = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
45
46 // when calling TeeInitFull
47 // TEE_DEVICE_TYPE_BDF - HECI device Bus Device Function
48
49#else /* _WIN32 */
50 #ifndef METEE_DLL
51 #define METEE_DLL_API
52 #else
53 #ifdef METEE_DLL_EXPORT
54 #define METEE_DLL_API __attribute__((__visibility__("default")))
55 #else
56 #define METEE_DLL_API
57 #endif /* METEE_DLL_EXPORT */
58 #endif /* METEE_DLL */
59 #define TEEAPI METEE_DLL_API
60
61 #ifndef GUID_DEFINED
62 #define GUID_DEFINED 1
63 typedef struct _GUID {
64 uint32_t l;
65 uint16_t w1;
66 uint16_t w2;
67 uint8_t b[8];
68 } GUID;
69 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
70 const GUID name \
71 = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
72 #endif /* GUID_DEFINED */
73
74 #define TEE_DEVICE_HANDLE int
75 #define TEE_INVALID_DEVICE_HANDLE (-1)
76 #ifndef IN
77 #define IN
78 #endif
79 #ifndef OUT
80 #define OUT
81 #endif
82 #ifndef OPTIONAL
83 #define OPTIONAL
84 #endif
85#endif /* _WIN32 */
87
90 enum tee_log_level {
91 TEE_LOG_LEVEL_QUIET = 0,
92 TEE_LOG_LEVEL_ERROR = 1,
93 TEE_LOG_LEVEL_VERBOSE = 2,
94 TEE_LOG_LEVEL_MAX = 3,
95};
96
100 typedef void(*TeeLogCallback)(bool is_error, const char* fmt, ...);
101
104 typedef void(*TeeLogCallback2)(bool is_error, const char* msg);
105
106#pragma pack(1)
107
111 typedef struct _TEEHANDLE {
112
113 void *handle;
114 size_t maxMsgLen;
115 uint8_t protcolVer;
116 enum tee_log_level log_level;
117 TeeLogCallback log_callback;
118 TeeLogCallback2 log_callback2;
119} TEEHANDLE;
120
125 typedef TEEHANDLE *PTEEHANDLE;
126
129 struct tee_device_address {
132 enum {
133 TEE_DEVICE_TYPE_NONE = 0,
134 TEE_DEVICE_TYPE_PATH = 1,
135 TEE_DEVICE_TYPE_HANDLE = 2,
136 TEE_DEVICE_TYPE_GUID = 3,
137 TEE_DEVICE_TYPE_BDF = 4,
138 TEE_DEVICE_TYPE_MAX = 5,
139 } type;
140
142 union {
143 const char* path;
144 const GUID* guid;
145 TEE_DEVICE_HANDLE handle;
146 struct {
147 struct {
148 uint32_t segment;
149 uint32_t bus;
150 uint32_t device;
151 uint32_t function;
152 } value;
154 enum HECI_HW_TYPE {
155 HECI_HW_TYPE_PCH,
156 HECI_HW_TYPE_GFX_GSC,
157 HECI_HW_TYPE_GFX_CSC,
158 } hw_type;
159 } bdf;
160 } data;
161};
162
163#pragma pack()
164
166#define TEEHANDLE_ZERO {0}
167
168 typedef uint16_t TEESTATUS;
170#define TEE_ERROR_BASE 0x0000U
172#define TEE_SUCCESS (TEE_ERROR_BASE + 0)
174#define TEE_INTERNAL_ERROR (TEE_ERROR_BASE + 1)
176#define TEE_DEVICE_NOT_FOUND (TEE_ERROR_BASE + 2)
178#define TEE_DEVICE_NOT_READY (TEE_ERROR_BASE + 3)
180#define TEE_INVALID_PARAMETER (TEE_ERROR_BASE + 4)
182#define TEE_UNABLE_TO_COMPLETE_OPERATION (TEE_ERROR_BASE + 5)
184#define TEE_TIMEOUT (TEE_ERROR_BASE + 6)
186#define TEE_NOTSUPPORTED (TEE_ERROR_BASE + 7)
188#define TEE_CLIENT_NOT_FOUND (TEE_ERROR_BASE + 8)
190#define TEE_BUSY (TEE_ERROR_BASE + 9)
192#define TEE_DISCONNECTED (TEE_ERROR_BASE + 10)
194#define TEE_INSUFFICIENT_BUFFER (TEE_ERROR_BASE + 11)
196#define TEE_PERMISSION_DENIED (TEE_ERROR_BASE + 12)
197
200#define TEE_IS_SUCCESS(Status) (((TEESTATUS)(Status)) == TEE_SUCCESS)
201
212 TEESTATUS TEEAPI TeeInitFull(IN OUT PTEEHANDLE handle, IN const GUID* guid,
213 IN const struct tee_device_address device,
214 IN uint32_t log_level, IN OPTIONAL TeeLogCallback log_callback);
215
225 TEESTATUS TEEAPI TeeInitFull2(IN OUT PTEEHANDLE handle, IN const GUID* guid,
226 IN const struct tee_device_address device,
227 IN uint32_t log_level, IN OPTIONAL TeeLogCallback2 log_callback);
228
236 TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID *guid,
237 IN OPTIONAL const char *device);
238
239#ifdef _WIN32
248 TEESTATUS TEEAPI TeeInitGUID(IN OUT PTEEHANDLE handle, IN const GUID *guid,
249 IN OPTIONAL const GUID *device);
250#endif /* _WIN32 */
251
259 TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID *guid,
260 IN const TEE_DEVICE_HANDLE device_handle);
261
266 TEESTATUS TEEAPI TeeConnect(OUT PTEEHANDLE handle);
267
277 TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void *buffer, IN size_t bufferSize,
278 OUT OPTIONAL size_t *pNumOfBytesRead, IN OPTIONAL uint32_t timeout);
279
289 TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void *buffer, IN size_t bufferSize,
290 OUT OPTIONAL size_t *numberOfBytesWritten, IN OPTIONAL uint32_t timeout);
291
298 TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle,
299 IN uint32_t fwStatusNum, OUT uint32_t *fwStatus);
300
306 TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t* trc_val);
307
313 void TEEAPI TeeDisconnect(IN PTEEHANDLE handle);
314
318 void TEEAPI TeeCancelIO(IN PTEEHANDLE handle);
319
325TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle);
326
329 typedef struct {
330 uint16_t major;
331 uint16_t minor;
332 uint16_t hotfix;
333 uint16_t build;
334} teeDriverVersion_t;
335
342 TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion);
343
350uint32_t TEEAPI TeeSetLogLevel(IN PTEEHANDLE handle, IN uint32_t log_level);
351
357uint32_t TEEAPI TeeGetLogLevel(IN const PTEEHANDLE handle);
358
365 TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback);
366
373 TEESTATUS TEEAPI TeeSetLogCallback2(IN const PTEEHANDLE handle, TeeLogCallback2 log_callback);
374
381uint32_t TEEAPI TeeGetMaxMsgLen(IN const PTEEHANDLE handle);
382
389uint8_t TEEAPI TeeGetProtocolVer(IN const PTEEHANDLE handle);
390
391
399 TEESTATUS TEEAPI TeeGetKind(IN PTEEHANDLE handle, IN OUT char *kind, IN OUT size_t *kindSize);
400
401#ifdef __cplusplus
402}
403#endif
404
405#endif /* __METEE_H */
TEESTATUS
uint16_t TEESTATUS
Definition metee.h:168
TeeLogCallback
void(* TeeLogCallback)(bool is_error, const char *fmt,...)
Definition metee.h:100
TeeLogCallback2
void(* TeeLogCallback2)(bool is_error, const char *msg)
Definition metee.h:104
TeeSetLogCallback
TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback)
TeeCancelIO
void TEEAPI TeeCancelIO(IN PTEEHANDLE handle)
tee_log_level
tee_log_level
Definition metee.h:90
TEE_LOG_LEVEL_ERROR
@ TEE_LOG_LEVEL_ERROR
Definition metee.h:92
TEE_LOG_LEVEL_MAX
@ TEE_LOG_LEVEL_MAX
Definition metee.h:94
TEE_LOG_LEVEL_VERBOSE
@ TEE_LOG_LEVEL_VERBOSE
Definition metee.h:93
TEE_LOG_LEVEL_QUIET
@ TEE_LOG_LEVEL_QUIET
Definition metee.h:91
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:125
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)
TeeInitFull2
TEESTATUS TEEAPI TeeInitFull2(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN const struct tee_device_address device, IN uint32_t log_level, IN OPTIONAL TeeLogCallback2 log_callback)
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)
TeeSetLogCallback2
TEESTATUS TEEAPI TeeSetLogCallback2(IN const PTEEHANDLE handle, TeeLogCallback2 log_callback)
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:111
_TEEHANDLE::protcolVer
uint8_t protcolVer
Definition metee.h:115
_TEEHANDLE::log_callback
TeeLogCallback log_callback
Definition metee.h:117
_TEEHANDLE::log_callback2
TeeLogCallback2 log_callback2
Definition metee.h:118
_TEEHANDLE::log_level
enum tee_log_level log_level
Definition metee.h:116
_TEEHANDLE::maxMsgLen
size_t maxMsgLen
Definition metee.h:114
_TEEHANDLE::handle
void * handle
Definition metee.h:113
teeDriverVersion_t
Definition metee.h:329
teeDriverVersion_t::major
uint16_t major
Definition metee.h:330
teeDriverVersion_t::build
uint16_t build
Definition metee.h:333
teeDriverVersion_t::minor
uint16_t minor
Definition metee.h:331
teeDriverVersion_t::hotfix
uint16_t hotfix
Definition metee.h:332
tee_device_address
Definition metee.h:129
tee_device_address::data
union tee_device_address::@216037340073175011262250131071152015074050034011 data
tee_device_address::device
uint32_t device
Definition metee.h:150
tee_device_address::function
uint32_t function
Definition metee.h:151
tee_device_address::handle
TEE_DEVICE_HANDLE handle
Definition metee.h:145
tee_device_address::bus
uint32_t bus
Definition metee.h:149
tee_device_address::TEE_DEVICE_TYPE_NONE
@ TEE_DEVICE_TYPE_NONE
Definition metee.h:133
tee_device_address::TEE_DEVICE_TYPE_GUID
@ TEE_DEVICE_TYPE_GUID
Definition metee.h:136
tee_device_address::TEE_DEVICE_TYPE_HANDLE
@ TEE_DEVICE_TYPE_HANDLE
Definition metee.h:135
tee_device_address::TEE_DEVICE_TYPE_PATH
@ TEE_DEVICE_TYPE_PATH
Definition metee.h:134
tee_device_address::TEE_DEVICE_TYPE_MAX
@ TEE_DEVICE_TYPE_MAX
Definition metee.h:138
tee_device_address::TEE_DEVICE_TYPE_BDF
@ TEE_DEVICE_TYPE_BDF
Definition metee.h:137
tee_device_address::guid
const GUID * guid
Definition metee.h:144
tee_device_address::type
enum tee_device_address::@117377034207052076013046012030027361103156100163 type