Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Amirreza Zarrabi and committed by
Jens Wiklander
0f7bfdcb d6e29083

+81 -5
+1
drivers/tee/qcomtee/Makefile
··· 3 3 qcomtee-objs += async.o 4 4 qcomtee-objs += call.o 5 5 qcomtee-objs += core.o 6 + qcomtee-objs += primordial_obj.o 6 7 qcomtee-objs += shm.o 7 8 qcomtee-objs += user_obj.o
+14 -5
drivers/tee/qcomtee/core.c
··· 31 31 } 32 32 33 33 /* 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. 36 37 */ 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) 38 40 #define QCOMTEE_OBJECT_ID_END (U32_MAX) 39 41 40 42 #define QCOMTEE_OBJECT_SET(p, type, ...) \ ··· 159 157 */ 160 158 int qcomtee_object_get(struct qcomtee_object *object) 161 159 { 162 - if (object != NULL_QCOMTEE_OBJECT && object != ROOT_QCOMTEE_OBJECT) 160 + if (object != &qcomtee_primordial_object && 161 + object != NULL_QCOMTEE_OBJECT && 162 + object != ROOT_QCOMTEE_OBJECT) 163 163 return kref_get_unless_zero(&object->refcount); 164 164 165 165 return 0; ··· 173 169 */ 174 170 void qcomtee_object_put(struct qcomtee_object *object) 175 171 { 176 - if (object != NULL_QCOMTEE_OBJECT && object != ROOT_QCOMTEE_OBJECT) 172 + if (object != &qcomtee_primordial_object && 173 + object != NULL_QCOMTEE_OBJECT && 174 + object != ROOT_QCOMTEE_OBJECT) 177 175 kref_put(&object->refcount, qcomtee_object_release); 178 176 } 179 177 ··· 266 260 { 267 261 struct qcomtee *qcomtee = tee_get_drvdata(oic->ctx->teedev); 268 262 struct qcomtee_object *object; 263 + 264 + if (object_id == QCOMTEE_OBJECT_PRIMORDIAL) 265 + return &qcomtee_primordial_object; 269 266 270 267 guard(rcu)(); 271 268 object = xa_load(&qcomtee->xa_local_objects, object_id);
+63
drivers/tee/qcomtee/primordial_obj.c
··· 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 + };
+3
drivers/tee/qcomtee/qcomtee.h
··· 140 140 struct tee_param *params, int num_params, 141 141 int req_id, int errno); 142 142 143 + /* (2) Primordial Object. */ 144 + extern struct qcomtee_object qcomtee_primordial_object; 145 + 143 146 #endif /* QCOMTEE_H */