1*1bb92983SJerome Forissier // SPDX-License-Identifier: BSD-2-Clause
2319556cdSPeng Fan /*
3319556cdSPeng Fan * Copyright (C) 2016 Freescale Semiconductor, Inc.
4319556cdSPeng Fan * All rights reserved.
5319556cdSPeng Fan *
6319556cdSPeng Fan * Peng Fan <peng.fan@nxp.com>
7319556cdSPeng Fan *
8319556cdSPeng Fan * Redistribution and use in source and binary forms, with or without
9319556cdSPeng Fan * modification, are permitted provided that the following conditions are met:
10319556cdSPeng Fan *
11319556cdSPeng Fan * 1. Redistributions of source code must retain the above copyright notice,
12319556cdSPeng Fan * this list of conditions and the following disclaimer.
13319556cdSPeng Fan *
14319556cdSPeng Fan * 2. Redistributions in binary form must reproduce the above copyright notice,
15319556cdSPeng Fan * this list of conditions and the following disclaimer in the documentation
16319556cdSPeng Fan * and/or other materials provided with the distribution.
17319556cdSPeng Fan *
18319556cdSPeng Fan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19319556cdSPeng Fan * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20319556cdSPeng Fan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21319556cdSPeng Fan * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22319556cdSPeng Fan * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23319556cdSPeng Fan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24319556cdSPeng Fan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25319556cdSPeng Fan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26319556cdSPeng Fan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27319556cdSPeng Fan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28319556cdSPeng Fan * POSSIBILITY OF SUCH DAMAGE.
29319556cdSPeng Fan */
30319556cdSPeng Fan
31319556cdSPeng Fan #include <stdint.h>
32319556cdSPeng Fan #include <sm/optee_smc.h>
33319556cdSPeng Fan #include <sm/psci.h>
34319556cdSPeng Fan #include <sm/sm.h>
35319556cdSPeng Fan #include <sm/std_smc.h>
36319556cdSPeng Fan #include <tee/uuid.h>
37319556cdSPeng Fan #include <trace.h>
38319556cdSPeng Fan
39319556cdSPeng Fan static const TEE_UUID uuid = {
40319556cdSPeng Fan 0x5f8b97df, 0x2d0d, 0x4ad2,
41319556cdSPeng Fan {0x98, 0xd2, 0x74, 0xf4, 0x38, 0x27, 0x98, 0xbb},
42319556cdSPeng Fan };
43319556cdSPeng Fan
smc_std_handler(struct thread_smc_args * args,struct sm_nsec_ctx * nsec)441b181fb2SPeng Fan void smc_std_handler(struct thread_smc_args *args, struct sm_nsec_ctx *nsec)
45319556cdSPeng Fan {
46319556cdSPeng Fan uint32_t smc_fid = args->a0;
47319556cdSPeng Fan
48319556cdSPeng Fan if (is_psci_fid(smc_fid)) {
491b181fb2SPeng Fan tee_psci_handler(args, nsec);
50319556cdSPeng Fan return;
51319556cdSPeng Fan }
52319556cdSPeng Fan
53319556cdSPeng Fan switch (smc_fid) {
54319556cdSPeng Fan case ARM_STD_SVC_CALL_COUNT:
55319556cdSPeng Fan /* PSCI is the only STD service implemented */
56319556cdSPeng Fan args->a0 = PSCI_NUM_CALLS;
57319556cdSPeng Fan break;
58319556cdSPeng Fan case ARM_STD_SVC_UID:
59319556cdSPeng Fan args->a0 = uuid.timeLow;
60319556cdSPeng Fan args->a1 = (uuid.timeHiAndVersion << 16) | uuid.timeMid;
61319556cdSPeng Fan args->a2 = (uuid.clockSeqAndNode[3] << 24) |
62319556cdSPeng Fan (uuid.clockSeqAndNode[2] << 16) |
63319556cdSPeng Fan (uuid.clockSeqAndNode[1] << 8) |
64319556cdSPeng Fan uuid.clockSeqAndNode[0];
65319556cdSPeng Fan args->a3 = (uuid.clockSeqAndNode[7] << 24) |
66319556cdSPeng Fan (uuid.clockSeqAndNode[6] << 16) |
67319556cdSPeng Fan (uuid.clockSeqAndNode[5] << 8) |
68319556cdSPeng Fan uuid.clockSeqAndNode[4];
69319556cdSPeng Fan break;
70319556cdSPeng Fan case ARM_STD_SVC_VERSION:
71319556cdSPeng Fan args->a0 = STD_SVC_VERSION_MAJOR;
72319556cdSPeng Fan args->a1 = STD_SVC_VERSION_MINOR;
73319556cdSPeng Fan break;
74319556cdSPeng Fan default:
75319556cdSPeng Fan args->a0 = OPTEE_SMC_RETURN_UNKNOWN_FUNCTION;
76319556cdSPeng Fan break;
77319556cdSPeng Fan }
78319556cdSPeng Fan }
79