xref: /optee_os/core/arch/arm/sm/std_smc.c (revision 8e81e2f5366a971afdd2ac47fb8529d1def5feb0)
1 /*
2  * Copyright (C) 2016 Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Peng Fan <peng.fan@nxp.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <stdint.h>
31 #include <sm/optee_smc.h>
32 #include <sm/psci.h>
33 #include <sm/sm.h>
34 #include <sm/std_smc.h>
35 #include <tee/uuid.h>
36 #include <trace.h>
37 
38 static const TEE_UUID uuid = {
39 	0x5f8b97df, 0x2d0d, 0x4ad2,
40 	{0x98, 0xd2, 0x74, 0xf4, 0x38, 0x27, 0x98, 0xbb},
41 };
42 
43 void smc_std_handler(struct thread_smc_args *args, struct sm_nsec_ctx *nsec)
44 {
45 	uint32_t smc_fid = args->a0;
46 
47 	if (is_psci_fid(smc_fid)) {
48 		tee_psci_handler(args, nsec);
49 		return;
50 	}
51 
52 	switch (smc_fid) {
53 	case ARM_STD_SVC_CALL_COUNT:
54 		/* PSCI is the only STD service implemented */
55 		args->a0 = PSCI_NUM_CALLS;
56 		break;
57 	case ARM_STD_SVC_UID:
58 		args->a0 = uuid.timeLow;
59 		args->a1 = (uuid.timeHiAndVersion << 16) | uuid.timeMid;
60 		args->a2 = (uuid.clockSeqAndNode[3] << 24) |
61 			(uuid.clockSeqAndNode[2] << 16) |
62 			(uuid.clockSeqAndNode[1] << 8) |
63 			uuid.clockSeqAndNode[0];
64 		args->a3 = (uuid.clockSeqAndNode[7] << 24) |
65 			(uuid.clockSeqAndNode[6] << 16) |
66 			(uuid.clockSeqAndNode[5] << 8) |
67 			uuid.clockSeqAndNode[4];
68 		break;
69 	case ARM_STD_SVC_VERSION:
70 		args->a0 = STD_SVC_VERSION_MAJOR;
71 		args->a1 = STD_SVC_VERSION_MINOR;
72 		break;
73 	default:
74 		args->a0 = OPTEE_SMC_RETURN_UNKNOWN_FUNCTION;
75 		break;
76 	}
77 }
78