securemsm-kernel: exposing smcinvoke headers
We are exposing headers present in "include/linux" for the rest of the kernel DLKM's. Aallow other kernel teams to access these headers. Change-Id: I19c5591d885c7042ba3acd312ce9cb2bddc995c9 CRS-Fixed: 3338788
This commit is contained in:

committed by
Gerrit - the friendly Code Review server

parent
8456ddc256
commit
9cd99dbb79
120
include/linux/IClientEnv.h
Normal file
120
include/linux/IClientEnv.h
Normal file
@@ -0,0 +1,120 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#define IClientEnv_OP_open 0
|
||||
#define IClientEnv_OP_registerLegacy 1
|
||||
#define IClientEnv_OP_register 2
|
||||
#define IClientEnv_OP_registerWithWhitelist 3
|
||||
#define IClientEnv_OP_notifyDomainChange 4
|
||||
#define IClientEnv_OP_registerWithCredentials 5
|
||||
|
||||
#include "smcinvoke_object.h"
|
||||
|
||||
static inline int32_t
|
||||
IClientEnv_release(struct Object self)
|
||||
{
|
||||
return Object_invoke(self, Object_OP_release, 0, 0);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IClientEnv_retain(struct Object self)
|
||||
{
|
||||
return Object_invoke(self, Object_OP_retain, 0, 0);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IClientEnv_open(struct Object self, uint32_t uid_val, struct Object *obj_ptr)
|
||||
{
|
||||
union ObjectArg a[2];
|
||||
int32_t result;
|
||||
|
||||
a[0].b = (struct ObjectBuf) { &uid_val, sizeof(uint32_t) };
|
||||
|
||||
result = Object_invoke(self, IClientEnv_OP_open, a, ObjectCounts_pack(1, 0, 0, 1));
|
||||
|
||||
*obj_ptr = a[1].o;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IClientEnv_registerLegacy(struct Object self, const void *credentials_ptr, size_t credentials_len,
|
||||
struct Object *clientEnv_ptr)
|
||||
{
|
||||
union ObjectArg a[2];
|
||||
int32_t result;
|
||||
|
||||
a[0].bi = (struct ObjectBufIn) { credentials_ptr, credentials_len * 1 };
|
||||
|
||||
result = Object_invoke(self, IClientEnv_OP_registerLegacy, a,
|
||||
ObjectCounts_pack(1, 0, 0, 1));
|
||||
|
||||
*clientEnv_ptr = a[1].o;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IClientEnv_register(struct Object self, struct Object credentials_val,
|
||||
struct Object *clientEnv_ptr)
|
||||
{
|
||||
union ObjectArg a[2];
|
||||
int32_t result;
|
||||
|
||||
a[0].o = credentials_val;
|
||||
|
||||
result = Object_invoke(self, IClientEnv_OP_register, a,
|
||||
ObjectCounts_pack(0, 0, 1, 1));
|
||||
|
||||
*clientEnv_ptr = a[1].o;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IClientEnv_registerWithWhitelist(struct Object self,
|
||||
struct Object credentials_val, const uint32_t *uids_ptr,
|
||||
size_t uids_len, struct Object *clientEnv_ptr)
|
||||
{
|
||||
union ObjectArg a[3];
|
||||
int32_t result;
|
||||
|
||||
a[1].o = credentials_val;
|
||||
a[0].bi = (struct ObjectBufIn) { uids_ptr, uids_len *
|
||||
sizeof(uint32_t) };
|
||||
|
||||
result = Object_invoke(self, IClientEnv_OP_registerWithWhitelist, a,
|
||||
ObjectCounts_pack(1, 0, 1, 1));
|
||||
|
||||
*clientEnv_ptr = a[2].o;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IClientEnv_notifyDomainChange(struct Object self)
|
||||
{
|
||||
return Object_invoke(self, IClientEnv_OP_notifyDomainChange, 0, 0);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IClientEnv_registerWithCredentials(struct Object self, struct Object
|
||||
credentials_val, struct Object *clientEnv_ptr)
|
||||
{
|
||||
union ObjectArg a[2]={{{0,0}}};
|
||||
int32_t result;
|
||||
|
||||
a[0].o = credentials_val;
|
||||
|
||||
result = Object_invoke(self, IClientEnv_OP_registerWithCredentials, a,
|
||||
ObjectCounts_pack(0, 0, 1, 1));
|
||||
|
||||
*clientEnv_ptr = a[1].o;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
103
include/linux/smcinvoke.h
Normal file
103
include/linux/smcinvoke.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
|
||||
/*
|
||||
* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
|
||||
*/
|
||||
#ifndef _UAPI_SMCINVOKE_H_
|
||||
#define _UAPI_SMCINVOKE_H_
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
#define SMCINVOKE_USERSPACE_OBJ_NULL -1
|
||||
|
||||
struct smcinvoke_buf {
|
||||
__u64 addr;
|
||||
__u64 size;
|
||||
};
|
||||
|
||||
struct smcinvoke_obj {
|
||||
__s64 fd;
|
||||
__s32 cb_server_fd;
|
||||
__s32 reserved;
|
||||
};
|
||||
|
||||
union smcinvoke_arg {
|
||||
struct smcinvoke_buf b;
|
||||
struct smcinvoke_obj o;
|
||||
};
|
||||
|
||||
/*
|
||||
* struct smcinvoke_cmd_req: This structure is transparently sent to TEE
|
||||
* @op - Operation to be performed
|
||||
* @counts - number of aruments passed
|
||||
* @result - result of invoke operation
|
||||
* @argsize - size of each of arguments
|
||||
* @args - args is pointer to buffer having all arguments
|
||||
*/
|
||||
struct smcinvoke_cmd_req {
|
||||
__u32 op;
|
||||
__u32 counts;
|
||||
__s32 result;
|
||||
__u32 argsize;
|
||||
__u64 args;
|
||||
};
|
||||
|
||||
/*
|
||||
* struct smcinvoke_accept: structure to process CB req from TEE
|
||||
* @has_resp: IN: Whether IOCTL is carrying response data
|
||||
* @txn_id: OUT: An id that should be passed as it is for response
|
||||
* @result: IN: Outcome of operation op
|
||||
* @cbobj_id: OUT: Callback object which is target of operation op
|
||||
* @op: OUT: Operation to be performed on target object
|
||||
* @counts: OUT: Number of arguments, embedded in buffer pointed by
|
||||
* buf_addr, to complete operation
|
||||
* @reserved: IN/OUT: Usage is not defined but should be set to 0.
|
||||
* @argsize: IN: Size of any argument, all of equal size, embedded
|
||||
* in buffer pointed by buf_addr
|
||||
* @buf_len: IN: Len of buffer pointed by buf_addr
|
||||
* @buf_addr: IN: Buffer containing all arguments which are needed
|
||||
* to complete operation op
|
||||
*/
|
||||
struct smcinvoke_accept {
|
||||
__u32 has_resp;
|
||||
__u32 txn_id;
|
||||
__s32 result;
|
||||
__s32 cbobj_id;
|
||||
__u32 op;
|
||||
__u32 counts;
|
||||
__s32 reserved;
|
||||
__u32 argsize;
|
||||
__u64 buf_len;
|
||||
__u64 buf_addr;
|
||||
};
|
||||
|
||||
/*
|
||||
* @cb_buf_size: IN: Max buffer size for any callback obj implemented by client
|
||||
*/
|
||||
struct smcinvoke_server {
|
||||
__u32 cb_buf_size;
|
||||
};
|
||||
|
||||
#define SMCINVOKE_IOC_MAGIC 0x98
|
||||
|
||||
#define SMCINVOKE_IOCTL_INVOKE_REQ \
|
||||
_IOWR(SMCINVOKE_IOC_MAGIC, 1, struct smcinvoke_cmd_req)
|
||||
|
||||
#define SMCINVOKE_IOCTL_ACCEPT_REQ \
|
||||
_IOWR(SMCINVOKE_IOC_MAGIC, 2, struct smcinvoke_accept)
|
||||
|
||||
#define SMCINVOKE_IOCTL_SERVER_REQ \
|
||||
_IOWR(SMCINVOKE_IOC_MAGIC, 3, struct smcinvoke_server)
|
||||
|
||||
#define SMCINVOKE_IOCTL_ACK_LOCAL_OBJ \
|
||||
_IOWR(SMCINVOKE_IOC_MAGIC, 4, __s32)
|
||||
|
||||
/*
|
||||
* smcinvoke logging buffer is for communicating with the smcinvoke driver additional
|
||||
* info for debugging to be included in driver's log (if any)
|
||||
*/
|
||||
#define SMCINVOKE_LOG_BUF_SIZE 100
|
||||
#define SMCINVOKE_IOCTL_LOG \
|
||||
_IOC(_IOC_READ|_IOC_WRITE, SMCINVOKE_IOC_MAGIC, 255, SMCINVOKE_LOG_BUF_SIZE)
|
||||
|
||||
#endif /* _UAPI_SMCINVOKE_H_ */
|
199
include/linux/smcinvoke_object.h
Normal file
199
include/linux/smcinvoke_object.h
Normal file
@@ -0,0 +1,199 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
|
||||
/*
|
||||
* Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
#ifndef __SMCINVOKE_OBJECT_H
|
||||
#define __SMCINVOKE_OBJECT_H
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/firmware.h>
|
||||
#include <linux/qtee_shmbridge.h>
|
||||
|
||||
/*
|
||||
* Method bits are not modified by transport layers. These describe the
|
||||
* method (member function) being requested by the client.
|
||||
*/
|
||||
|
||||
#define OBJECT_OP_METHOD_MASK (0x0000FFFFu)
|
||||
#define OBJECT_OP_METHODID(op) ((op) & OBJECT_OP_METHOD_MASK)
|
||||
#define OBJECT_OP_RELEASE (OBJECT_OP_METHOD_MASK - 0)
|
||||
#define OBJECT_OP_RETAIN (OBJECT_OP_METHOD_MASK - 1)
|
||||
#define OBJECT_OP_MAP_REGION 0
|
||||
#define OBJECT_OP_YIELD 1
|
||||
#define OBJECT_OP_SLEEP 2
|
||||
|
||||
#define OBJECT_COUNTS_MAX_BI 0xF
|
||||
#define OBJECT_COUNTS_MAX_BO 0xF
|
||||
#define OBJECT_COUNTS_MAX_OI 0xF
|
||||
#define OBJECT_COUNTS_MAX_OO 0xF
|
||||
|
||||
/* unpack counts */
|
||||
|
||||
#define OBJECT_COUNTS_NUM_BI(k) ((size_t) (((k) >> 0) & OBJECT_COUNTS_MAX_BI))
|
||||
#define OBJECT_COUNTS_NUM_BO(k) ((size_t) (((k) >> 4) & OBJECT_COUNTS_MAX_BO))
|
||||
#define OBJECT_COUNTS_NUM_OI(k) ((size_t) (((k) >> 8) & OBJECT_COUNTS_MAX_OI))
|
||||
#define OBJECT_COUNTS_NUM_OO(k) ((size_t) (((k) >> 12) & OBJECT_COUNTS_MAX_OO))
|
||||
#define OBJECT_COUNTS_NUM_buffers(k) \
|
||||
(OBJECT_COUNTS_NUM_BI(k) + OBJECT_COUNTS_NUM_BO(k))
|
||||
|
||||
#define OBJECT_COUNTS_NUM_objects(k) \
|
||||
(OBJECT_COUNTS_NUM_OI(k) + OBJECT_COUNTS_NUM_OO(k))
|
||||
|
||||
/* Indices into args[] */
|
||||
|
||||
#define OBJECT_COUNTS_INDEX_BI(k) 0
|
||||
#define OBJECT_COUNTS_INDEX_BO(k) \
|
||||
(OBJECT_COUNTS_INDEX_BI(k) + OBJECT_COUNTS_NUM_BI(k))
|
||||
#define OBJECT_COUNTS_INDEX_OI(k) \
|
||||
(OBJECT_COUNTS_INDEX_BO(k) + OBJECT_COUNTS_NUM_BO(k))
|
||||
#define OBJECT_COUNTS_INDEX_OO(k) \
|
||||
(OBJECT_COUNTS_INDEX_OI(k) + OBJECT_COUNTS_NUM_OI(k))
|
||||
#define OBJECT_COUNTS_TOTAL(k) \
|
||||
(OBJECT_COUNTS_INDEX_OO(k) + OBJECT_COUNTS_NUM_OO(k))
|
||||
|
||||
#define OBJECT_COUNTS_PACK(in_bufs, out_bufs, in_objs, out_objs) \
|
||||
((uint32_t) ((in_bufs) | ((out_bufs) << 4) | \
|
||||
((in_objs) << 8) | ((out_objs) << 12)))
|
||||
|
||||
#define OBJECT_COUNTS_INDEX_buffers(k) OBJECT_COUNTS_INDEX_BI(k)
|
||||
|
||||
/* Object_invoke return codes */
|
||||
|
||||
#define OBJECT_isOK(err) ((err) == 0)
|
||||
#define OBJECT_isERROR(err) ((err) != 0)
|
||||
|
||||
/* Generic error codes */
|
||||
|
||||
#define OBJECT_OK 0 /* non-specific success code */
|
||||
#define OBJECT_ERROR 1 /* non-specific error */
|
||||
#define OBJECT_ERROR_INVALID 2 /* unsupported/unrecognized request */
|
||||
#define OBJECT_ERROR_SIZE_IN 3 /* supplied buffer/string too large */
|
||||
#define OBJECT_ERROR_SIZE_OUT 4 /* supplied output buffer too small */
|
||||
|
||||
#define OBJECT_ERROR_USERBASE 10 /* start of user-defined error range */
|
||||
|
||||
/* Transport layer error codes */
|
||||
|
||||
#define OBJECT_ERROR_DEFUNCT -90 /* object no longer exists */
|
||||
#define OBJECT_ERROR_ABORT -91 /* calling thread must exit */
|
||||
#define OBJECT_ERROR_BADOBJ -92 /* invalid object context */
|
||||
#define OBJECT_ERROR_NOSLOTS -93 /* caller's object table full */
|
||||
#define OBJECT_ERROR_MAXARGS -94 /* too many args */
|
||||
#define OBJECT_ERROR_MAXDATA -95 /* buffers too large */
|
||||
#define OBJECT_ERROR_UNAVAIL -96 /* the request could not be processed */
|
||||
#define OBJECT_ERROR_KMEM -97 /* kernel out of memory */
|
||||
#define OBJECT_ERROR_REMOTE -98 /* local method sent to remote object */
|
||||
#define OBJECT_ERROR_BUSY -99 /* Object is busy */
|
||||
#define Object_ERROR_TIMEOUT -103 /* Call Back Object invocation timed out. */
|
||||
|
||||
#define FOR_ARGS(ndxvar, counts, section) \
|
||||
for (ndxvar = OBJECT_COUNTS_INDEX_##section(counts); \
|
||||
ndxvar < (OBJECT_COUNTS_INDEX_##section(counts) \
|
||||
+ OBJECT_COUNTS_NUM_##section(counts)); \
|
||||
++ndxvar)
|
||||
|
||||
/* ObjectOp */
|
||||
|
||||
#define ObjectOp_METHOD_MASK ((uint32_t) 0x0000FFFFu)
|
||||
#define ObjectOp_methodID(op) ((op) & ObjectOp_METHOD_MASK)
|
||||
|
||||
#define ObjectOp_LOCAL ((uint32_t) 0x00008000U)
|
||||
|
||||
#define ObjectOp_isLocal(op) (((op) & ObjectOp_LOCAL) != 0)
|
||||
|
||||
|
||||
#define Object_OP_release (ObjectOp_METHOD_MASK - 0)
|
||||
#define Object_OP_retain (ObjectOp_METHOD_MASK - 1)
|
||||
|
||||
/* Object */
|
||||
|
||||
#define ObjectCounts_pack(nBuffersIn, nBuffersOut, nObjectsIn, nObjectsOut) \
|
||||
((uint32_t) ((nBuffersIn) | \
|
||||
((nBuffersOut) << 4) | \
|
||||
((nObjectsIn) << 8) | \
|
||||
((nObjectsOut) << 12)))
|
||||
|
||||
union ObjectArg;
|
||||
|
||||
typedef int32_t (*ObjectInvoke)(void *h,
|
||||
uint32_t op,
|
||||
union ObjectArg *args,
|
||||
uint32_t counts);
|
||||
|
||||
struct Object {
|
||||
ObjectInvoke invoke;
|
||||
void *context;
|
||||
};
|
||||
|
||||
struct ObjectBuf {
|
||||
void *ptr;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct ObjectBufIn {
|
||||
const void *ptr;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
union ObjectArg {
|
||||
struct ObjectBuf b;
|
||||
struct ObjectBufIn bi;
|
||||
struct Object o;
|
||||
};
|
||||
|
||||
static inline int32_t Object_invoke(struct Object o, uint32_t op,
|
||||
union ObjectArg *args, uint32_t k)
|
||||
{
|
||||
return o.invoke(o.context, op, args, k);
|
||||
}
|
||||
|
||||
#define Object_NULL ((struct Object){NULL, NULL})
|
||||
|
||||
|
||||
#define OBJECT_NOT_RETAINED
|
||||
|
||||
#define OBJECT_CONSUMED
|
||||
|
||||
static inline int32_t Object_release(OBJECT_CONSUMED struct Object o)
|
||||
{
|
||||
return Object_invoke((o), Object_OP_release, 0, 0);
|
||||
}
|
||||
static inline int32_t Object_retain(struct Object o)
|
||||
{
|
||||
return Object_invoke((o), Object_OP_retain, 0, 0);
|
||||
}
|
||||
|
||||
#define Object_isNull(o) ((o).invoke == NULL)
|
||||
|
||||
#define Object_RELEASE_IF(o) \
|
||||
do { \
|
||||
struct Object o_ = (o); \
|
||||
if (!Object_isNull(o_)) \
|
||||
(void) Object_release(o_); \
|
||||
} while (0)
|
||||
|
||||
static inline void Object_replace(struct Object *loc, struct Object objNew)
|
||||
{
|
||||
if (!Object_isNull(*loc))
|
||||
Object_release(*loc);
|
||||
|
||||
if (!Object_isNull(objNew))
|
||||
Object_retain(objNew);
|
||||
*loc = objNew;
|
||||
}
|
||||
|
||||
#define Object_ASSIGN_NULL(loc) Object_replace(&(loc), Object_NULL)
|
||||
|
||||
int smcinvoke_release_from_kernel_client(int fd);
|
||||
|
||||
int get_root_fd(int *root_fd);
|
||||
|
||||
int process_invoke_request_from_kernel_client(
|
||||
int fd, struct smcinvoke_cmd_req *req);
|
||||
|
||||
char *firmware_request_from_smcinvoke(const char *appname, size_t *fw_size, struct qtee_shm *shm);
|
||||
|
||||
int32_t get_client_env_object(struct Object *clientEnvObj);
|
||||
|
||||
#endif /* __SMCINVOKE_OBJECT_H */
|
Reference in New Issue
Block a user