Skip to content

Commit 0f7bfdc

Browse files
qc-azarrabijenswi-linaro
authored andcommitted
tee: qcom: add primordial object
After booting, the kernel provides a static object known as the primordial object. This object is utilized by QTEE for native kernel services such as yield or privileged operations. Acked-by: Sumit Garg <sumit.garg@oss.qualcomm.com> Tested-by: Neil Armstrong <neil.armstrong@linaro.org> Tested-by: Harshal Dev <quic_hdev@quicinc.com> Signed-off-by: Amirreza Zarrabi <amirreza.zarrabi@oss.qualcomm.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
1 parent d6e2908 commit 0f7bfdc

4 files changed

Lines changed: 81 additions & 5 deletions

File tree

drivers/tee/qcomtee/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ obj-$(CONFIG_QCOMTEE) += qcomtee.o
33
qcomtee-objs += async.o
44
qcomtee-objs += call.o
55
qcomtee-objs += core.o
6+
qcomtee-objs += primordial_obj.o
67
qcomtee-objs += shm.o
78
qcomtee-objs += user_obj.o

drivers/tee/qcomtee/core.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ int qcomtee_next_arg_type(struct qcomtee_arg *u, int i,
3131
}
3232

3333
/*
34-
* QTEE expects IDs with the QCOMTEE_MSG_OBJECT_NS_BIT set for objects
35-
* of the QCOMTEE_OBJECT_TYPE_CB type.
34+
* QTEE expects IDs with QCOMTEE_MSG_OBJECT_NS_BIT set for objects of
35+
* QCOMTEE_OBJECT_TYPE_CB type. The first ID with QCOMTEE_MSG_OBJECT_NS_BIT
36+
* set is reserved for the primordial object.
3637
*/
37-
#define QCOMTEE_OBJECT_ID_START (QCOMTEE_MSG_OBJECT_NS_BIT + 1)
38+
#define QCOMTEE_OBJECT_PRIMORDIAL (QCOMTEE_MSG_OBJECT_NS_BIT)
39+
#define QCOMTEE_OBJECT_ID_START (QCOMTEE_OBJECT_PRIMORDIAL + 1)
3840
#define QCOMTEE_OBJECT_ID_END (U32_MAX)
3941

4042
#define QCOMTEE_OBJECT_SET(p, type, ...) \
@@ -157,7 +159,9 @@ static void qcomtee_object_release(struct kref *refcount)
157159
*/
158160
int qcomtee_object_get(struct qcomtee_object *object)
159161
{
160-
if (object != NULL_QCOMTEE_OBJECT && object != ROOT_QCOMTEE_OBJECT)
162+
if (object != &qcomtee_primordial_object &&
163+
object != NULL_QCOMTEE_OBJECT &&
164+
object != ROOT_QCOMTEE_OBJECT)
161165
return kref_get_unless_zero(&object->refcount);
162166

163167
return 0;
@@ -169,7 +173,9 @@ int qcomtee_object_get(struct qcomtee_object *object)
169173
*/
170174
void qcomtee_object_put(struct qcomtee_object *object)
171175
{
172-
if (object != NULL_QCOMTEE_OBJECT && object != ROOT_QCOMTEE_OBJECT)
176+
if (object != &qcomtee_primordial_object &&
177+
object != NULL_QCOMTEE_OBJECT &&
178+
object != ROOT_QCOMTEE_OBJECT)
173179
kref_put(&object->refcount, qcomtee_object_release);
174180
}
175181

@@ -261,6 +267,9 @@ qcomtee_local_object_get(struct qcomtee_object_invoke_ctx *oic,
261267
struct qcomtee *qcomtee = tee_get_drvdata(oic->ctx->teedev);
262268
struct qcomtee_object *object;
263269

270+
if (object_id == QCOMTEE_OBJECT_PRIMORDIAL)
271+
return &qcomtee_primordial_object;
272+
264273
guard(rcu)();
265274
object = xa_load(&qcomtee->xa_local_objects, object_id);
266275
/* It already checks for %NULL_QCOMTEE_OBJECT. */
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
*/
5+
6+
#include <linux/delay.h>
7+
#include "qcomtee.h"
8+
9+
/**
10+
* DOC: Primordial Object
11+
*
12+
* After boot, the kernel provides a static object of type
13+
* %QCOMTEE_OBJECT_TYPE_CB called the primordial object. This object is used
14+
* for native kernel services or privileged operations.
15+
*
16+
* We support:
17+
* - %QCOMTEE_OBJECT_OP_YIELD to yield by the thread running in QTEE.
18+
* - %QCOMTEE_OBJECT_OP_SLEEP to wait for a period of time.
19+
*/
20+
21+
#define QCOMTEE_OBJECT_OP_YIELD 1
22+
#define QCOMTEE_OBJECT_OP_SLEEP 2
23+
24+
static int
25+
qcomtee_primordial_obj_dispatch(struct qcomtee_object_invoke_ctx *oic,
26+
struct qcomtee_object *primordial_object_unused,
27+
u32 op, struct qcomtee_arg *args)
28+
{
29+
int err = 0;
30+
31+
switch (op) {
32+
case QCOMTEE_OBJECT_OP_YIELD:
33+
cond_resched();
34+
/* No output object. */
35+
oic->data = NULL;
36+
break;
37+
case QCOMTEE_OBJECT_OP_SLEEP:
38+
/* Check message format matched QCOMTEE_OBJECT_OP_SLEEP op. */
39+
if (qcomtee_args_len(args) != 1 ||
40+
args[0].type != QCOMTEE_ARG_TYPE_IB ||
41+
args[0].b.size < sizeof(u32))
42+
return -EINVAL;
43+
44+
msleep(*(u32 *)(args[0].b.addr));
45+
/* No output object. */
46+
oic->data = NULL;
47+
break;
48+
default:
49+
err = -EINVAL;
50+
}
51+
52+
return err;
53+
}
54+
55+
static struct qcomtee_object_operations qcomtee_primordial_obj_ops = {
56+
.dispatch = qcomtee_primordial_obj_dispatch,
57+
};
58+
59+
struct qcomtee_object qcomtee_primordial_object = {
60+
.name = "primordial",
61+
.object_type = QCOMTEE_OBJECT_TYPE_CB,
62+
.ops = &qcomtee_primordial_obj_ops
63+
};

drivers/tee/qcomtee/qcomtee.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,7 @@ int qcomtee_user_object_submit(struct tee_context *ctx,
140140
struct tee_param *params, int num_params,
141141
int req_id, int errno);
142142

143+
/* (2) Primordial Object. */
144+
extern struct qcomtee_object qcomtee_primordial_object;
145+
143146
#endif /* QCOMTEE_H */

0 commit comments

Comments
 (0)