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
96 typedef void(*TeeLogCallback)(bool is_error, const char* fmt, ...);
97
100 typedef void(*TeeLogCallback2)(bool is_error, const char* msg);
101
102#pragma pack(1)
103
107 typedef struct _TEEHANDLE {
108
109 void *handle;
110 size_t maxMsgLen;
111 uint8_t protcolVer;
112 enum tee_log_level log_level;
113 TeeLogCallback log_callback;
114 TeeLogCallback2 log_callback2;
115} TEEHANDLE;
116
121 typedef TEEHANDLE *PTEEHANDLE;
122
125 struct tee_device_address {
128 enum {
129 TEE_DEVICE_TYPE_NONE = 0,
130 TEE_DEVICE_TYPE_PATH = 1,
131 TEE_DEVICE_TYPE_HANDLE = 2,
132 TEE_DEVICE_TYPE_GUID = 3,
133 TEE_DEVICE_TYPE_BDF = 4,
134 TEE_DEVICE_TYPE_MAX = 5,
135 } type;
136
138 union {
139 const char* path;
140 const GUID* guid;
141 TEE_DEVICE_HANDLE handle;
142 struct {
143 struct {
144 uint32_t segment;
145 uint32_t bus;
146 uint32_t device;
147 uint32_t function;
148 } value;
150 enum HECI_HW_TYPE {
151 HECI_HW_TYPE_PCH,
152 HECI_HW_TYPE_GFX_GSC,
153 HECI_HW_TYPE_GFX_CSC,
154 } hw_type;
155 } bdf;
156 } data;
157};
158
159#pragma pack()
160
162#define TEEHANDLE_ZERO {0}
163
164 typedef uint16_t TEESTATUS;
166#define TEE_ERROR_BASE 0x0000U
168#define TEE_SUCCESS (TEE_ERROR_BASE + 0)
170#define TEE_INTERNAL_ERROR (TEE_ERROR_BASE + 1)
172#define TEE_DEVICE_NOT_FOUND (TEE_ERROR_BASE + 2)
174#define TEE_DEVICE_NOT_READY (TEE_ERROR_BASE + 3)
176#define TEE_INVALID_PARAMETER (TEE_ERROR_BASE + 4)
178#define TEE_UNABLE_TO_COMPLETE_OPERATION (TEE_ERROR_BASE + 5)
180#define TEE_TIMEOUT (TEE_ERROR_BASE + 6)
182#define TEE_NOTSUPPORTED (TEE_ERROR_BASE + 7)
184#define TEE_CLIENT_NOT_FOUND (TEE_ERROR_BASE + 8)
186#define TEE_BUSY (TEE_ERROR_BASE + 9)
188#define TEE_DISCONNECTED (TEE_ERROR_BASE + 10)
190#define TEE_INSUFFICIENT_BUFFER (TEE_ERROR_BASE + 11)
192#define TEE_PERMISSION_DENIED (TEE_ERROR_BASE + 12)
193
196#define TEE_IS_SUCCESS(Status) (((TEESTATUS)(Status)) == TEE_SUCCESS)
197
208 TEESTATUS TEEAPI TeeInitFull(IN OUT PTEEHANDLE handle, IN const GUID* guid,
209 IN const struct tee_device_address device,
210 IN uint32_t log_level, IN OPTIONAL TeeLogCallback log_callback);
211
221 TEESTATUS TEEAPI TeeInitFull2(IN OUT PTEEHANDLE handle, IN const GUID* guid,
222 IN const struct tee_device_address device,
223 IN uint32_t log_level, IN OPTIONAL TeeLogCallback2 log_callback);
224
232 TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID *guid,
233 IN OPTIONAL const char *device);
234
235#ifdef _WIN32
244 TEESTATUS TEEAPI TeeInitGUID(IN OUT PTEEHANDLE handle, IN const GUID *guid,
245 IN OPTIONAL const GUID *device);
246#endif /* _WIN32 */
247
255 TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID *guid,
256 IN const TEE_DEVICE_HANDLE device_handle);
257
262 TEESTATUS TEEAPI TeeConnect(OUT PTEEHANDLE handle);
263
273 TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void *buffer, IN size_t bufferSize,
274 OUT OPTIONAL size_t *pNumOfBytesRead, IN OPTIONAL uint32_t timeout);
275
285 TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void *buffer, IN size_t bufferSize,
286 OUT OPTIONAL size_t *numberOfBytesWritten, IN OPTIONAL uint32_t timeout);
287
294 TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle,
295 IN uint32_t fwStatusNum, OUT uint32_t *fwStatus);
296
302 TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t* trc_val);
303
309 void TEEAPI TeeDisconnect(IN PTEEHANDLE handle);
310
314 void TEEAPI TeeCancelIO(IN PTEEHANDLE handle);
315
321TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle);
322
325 typedef struct {
326 uint16_t major;
327 uint16_t minor;
328 uint16_t hotfix;
329 uint16_t build;
330} teeDriverVersion_t;
331
338 TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion);
339
346uint32_t TEEAPI TeeSetLogLevel(IN PTEEHANDLE handle, IN uint32_t log_level);
347
353uint32_t TEEAPI TeeGetLogLevel(IN const PTEEHANDLE handle);
354
361 TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback);
362
369 TEESTATUS TEEAPI TeeSetLogCallback2(IN const PTEEHANDLE handle, TeeLogCallback2 log_callback);
370
377uint32_t TEEAPI TeeGetMaxMsgLen(IN const PTEEHANDLE handle);
378
385uint8_t TEEAPI TeeGetProtocolVer(IN const PTEEHANDLE handle);
386
387
395 TEESTATUS TEEAPI TeeGetKind(IN PTEEHANDLE handle, IN OUT char *kind, IN OUT size_t *kindSize);
396
397#ifdef __cplusplus
398}
399#endif
400
401#endif /* __METEE_H */
TEESTATUS
uint16_t TEESTATUS
Definition metee.h:164
TeeLogCallback
void(* TeeLogCallback)(bool is_error, const char *fmt,...)
Definition metee.h:96
TeeLogCallback2
void(* TeeLogCallback2)(bool is_error, const char *msg)
Definition metee.h:100
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: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:121
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:107
_TEEHANDLE::protcolVer
uint8_t protcolVer
Definition metee.h:111
_TEEHANDLE::log_callback
TeeLogCallback log_callback
Definition metee.h:113
_TEEHANDLE::log_callback2
TeeLogCallback2 log_callback2
Definition metee.h:114
_TEEHANDLE::log_level
enum tee_log_level log_level
Definition metee.h:112
_TEEHANDLE::maxMsgLen
size_t maxMsgLen
Definition metee.h:110
_TEEHANDLE::handle
void * handle
Definition metee.h:109
teeDriverVersion_t
Definition metee.h:325
teeDriverVersion_t::major
uint16_t major
Definition metee.h:326
teeDriverVersion_t::build
uint16_t build
Definition metee.h:329
teeDriverVersion_t::minor
uint16_t minor
Definition metee.h:327
teeDriverVersion_t::hotfix
uint16_t hotfix
Definition metee.h:328
tee_device_address
Definition metee.h:125
tee_device_address::device
uint32_t device
Definition metee.h:146
tee_device_address::type
enum tee_device_address::@042253021040273371057337303163200200023326002202 type
tee_device_address::function
uint32_t function
Definition metee.h:147
tee_device_address::handle
TEE_DEVICE_HANDLE handle
Definition metee.h:141
tee_device_address::bus
uint32_t bus
Definition metee.h:145
tee_device_address::TEE_DEVICE_TYPE_NONE
@ TEE_DEVICE_TYPE_NONE
Definition metee.h:129
tee_device_address::TEE_DEVICE_TYPE_GUID
@ TEE_DEVICE_TYPE_GUID
Definition metee.h:132
tee_device_address::TEE_DEVICE_TYPE_HANDLE
@ TEE_DEVICE_TYPE_HANDLE
Definition metee.h:131
tee_device_address::TEE_DEVICE_TYPE_PATH
@ TEE_DEVICE_TYPE_PATH
Definition metee.h:130
tee_device_address::TEE_DEVICE_TYPE_MAX
@ TEE_DEVICE_TYPE_MAX
Definition metee.h:134
tee_device_address::TEE_DEVICE_TYPE_BDF
@ TEE_DEVICE_TYPE_BDF
Definition metee.h:133
tee_device_address::data
union tee_device_address::@356113022115361343357150020345306326311217213270 data
tee_device_address::guid
const GUID * guid
Definition metee.h:140